RE: [ZODB-Dev] Re: SVN: ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/ Implements the ordering of before commit subscribers :

2005-08-08 Thread Tim Peters
[Julien Anguenot]
 +def beforeCommitHookOrdered(hook, order, *args, **kws):
 +
 Register a hook to call before the transaction is committed. ...
 +Note, a hook __call__() method can't define any 'order' argument
since
 +this one is reserved by this method

[Florent Guillaume]
 If that's a concern, maybe it can be called order__ or something ? What's
 the pythonic way to do this ?

It would be more accurate to say that the hook's __call__ method can't be
invoked with a keyword argument named `order`.  The same is equally true of
invoking it with a keyword argument named `hook`.  There's no problem if
__call__ defines arguments named `hook` and/or `order` provided those are
passed positionally to __call__.

The problem (such as it is) is really inherited from the older function:

def beforeCommitHook(self, hook, *args, **kws):

The most Pythonic way would have been to define that as

def beforeCommitHook(self, hook, args=(), kws=None):
if kws is None:
kws = {}

much like Python's thread.start_new_thread() and threading.Thread()
constructor.  Then Julien could have added an optional new `order=0`
argument to the old function too (instead of creating an additional
function).

While not ideal, it's minor, and naming the fixed arguments (in both
methods), e.g., __hook and __order would remove most of the little ugliness.

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


RE: [ZODB-Dev] Re: SVN: ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/ Implements the ordering of before commit subscribers :

2005-08-08 Thread Tim Peters
[Julien Anguenot]
 Zope3 seems to use one (1) underscore as a suffix like in :

 See for instance this :

http://svn.zope.org/Zope3/trunk/src/zope/app/component/metaconfigure.py?rev=
37586view=auto

  def subscriber(_context, for_=None, factory=None, handler=None,
 provides=None, permission=None, trusted=False, locate=False):
 

That's a semi-standard convention for dealing with names that conflict with
Python keywords (it's a syntax error to name an argument for -- or def
or while, etc).

 But here, the problem is, as well, the method's signature and backward
 compatibility for the beforeCommitHook() method since the only way to do
 it would be to extract the order_ from the **kws and then remove it
 before storing the hook info in the data structure which doesn't provide
 really a nice implementation in my opinion...

Yup, it gets ugly ;-)

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev