[Python-Dev] Re: decorators and 2.4
barry at python.org
Mon Jun 28 13:19:31 EDT 2004
On Mon, 2004-06-28 at 12:50, Jeff Bone wrote:
> > Just one more opinion here, but I'm with Bob on this one. Sure, many
> > of the uses I envision are "declarative" in the sense that they just
> > associate metadata with the function. But many other uses I envision
> > would alter the function's behavior.
> I'm really curious what these uses might be.
Here's one of my use case.
In the Mailman3 implementation of the BerkeleyDB backend storage, I need
to set up Berkeley transactions around various calls. It's
programmatically possible to set up an explicit transaction to group
several operations together, but it's also possible to wrap a single
operation in a single transaction. Also, the Berkeley transactions must
be wrapped in try/excepts so that if any Python level exception occurs,
the transaction can be properly aborted.
There's enough complexity in the implementation, and similarity in the
use, that I wanted to encapsulate all that in a 'txnprop' decorator. I
currently use the 'call-after-def' wrapper idiom that's possible in
Python 2.3 today, but I want to use decorators for this, especially
because I sometimes want to combine the txnprop wrapper with other
Here's a pointer to some of the code:
The txnprop() descriptor guarantees that self.txn is bound to a
transaction inside the method call.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 307 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-dev/attachments/20040628/80ff73a9/attachment.bin
More information about the Python-Dev