Maybe, just maybe @decorator syntax is ok after all

Hamish Lawson hbl at st-andrews.ac.uk
Tue Aug 10 20:01:21 CEST 2004


artur_spruce at yahoo.com (AdSR) wrote:
> bokr at oz.net (Bengt Richter) wrote in message news:<cf87jt$bra$0$216.39.172.122 at theriver.com>...
> > On 9 Aug 2004 07:07:54 -0700, artur_spruce at yahoo.com (AdSR) wrote:
> > <snip>
> > >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?
> 
> http://www.python.org/dev/doc/devel/ref/function.html

That part of the reference manual says:

"""
If there are multiple decorators, they are applied in reverse order.
For example, the following code:

@f1
@f2
def func(): pass

is equivalent to:

def func(): pass
func = f2(f1(func))
"""

I believe that in the example the author may have got confused by the
visual appearance of the expression f2(f1(func)). It's the order of
*application* that is the key thing and this expression actually has
f1 being applied first, rather than f2 as mandated by the "apply in
reverse order" rule. The example should instead have given the
equivalent expression as f1(f2(func)).


Hamish Lawson



More information about the Python-list mailing list