[Python-Dev] Re: new syntax for wrapping (PEP 318)

Bob Ippolito bob at redivi.com
Thu Feb 26 21:14:40 EST 2004

On Feb 26, 2004, at 8:58 PM, Barry Warsaw wrote:

> On Thu, 2004-02-26 at 18:43, Delaney, Timothy C (Timothy) wrote:
>> This isn't too bad. Probably better with a wrapper around sys.atexit -
>> something like:
>>     def atexit (func):
>>         sys.atexit(func)
>>         return func
>>     def cleanup() [atexit]:
>> otherwise it's not obvious that cleanup gets bound to None. Perhaps it
>> should be a requirement of decorators that they return something other
>> than None, and an exception is thrown if this contract is broken?
> Would it be better if it returned 1? <wink>
> Just what /is/ the contract for a decorator function?  Maybe that it
> takes a function/method object and must return a descriptor?  I do 
> think
> this needs some clarification in the PEP.

Why bother?  it doesn't have to be used inside of a class body, it 
shouldn't have to return a descriptor.

It's pretty obvious that some of the most useful purposes include 
wrapping a function in some kind of closure (like synchronized) or 
returning a descriptor (like classmethod).. but who knows what else it 
might be useful for, especially when used on classes themselves, as the 
patch being kicked around allows you to do (I imagine it would be the 
end to some metaclass abuses, for example).


More information about the Python-Dev mailing list