Maybe, just maybe @decorator syntax is ok after all

Bengt Richter bokr at oz.net
Mon Aug 9 18:09:33 CEST 2004


On 9 Aug 2004 07:07:54 -0700, artur_spruce at yahoo.com (AdSR) wrote:

>artur_spruce at yahoo.com (AdSR) wrote in message news:<b840abf4.0408080422.44fcf41c at posting.google.com>...
>> <snip>
>> @dec1
>> @dec2
>> def foo():
>>     pass
>> 
>> <snip> 
>> 
>> and after the second:
>> 
>> def foo():
>>     pass
>> 
>> foo = dec2(foo)
>> 
>> foo = dec1(foo)
>
>The latter is equivalent to:
>
>def foo():
>    pass
>foo = dec1(dec2(foo))
>
>But I've just noticed that the spec says:
>
>"""
>@f1
>@f2
>def func(): pass
>
>is equivalent to:
>
>def func(): pass
>func = f2(f1(func))
>"""
>
>So the order is reverse, which breaks my previous interpretation. Oh, well...
>
I think your example is not from the PEP. What "spec" are you citing?
Note the order in the example cut and pasted from the current
(Last-Modified:	2004/08/06 18:34:15) pep 318:
----
The current syntax for function decorators as implemented in Python 2.4a2 is:

@dec2
@dec1
def func(arg1, arg2, ...):
    pass

This is equivalent to:

def func(arg1, arg2, ...):
    pass
func = dec2(dec1(func))
----

Regards,
Bengt Richter



More information about the Python-list mailing list