Maybe, just maybe @decorator syntax is ok after all

Hamish Lawson hbl at
Tue Aug 10 20:01:21 CEST 2004

artur_spruce at (AdSR) wrote:
> bokr at (Bengt Richter) wrote in message news:<cf87jt$bra$0$ at>...
> > On 9 Aug 2004 07:07:54 -0700, artur_spruce at (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?

That part of the reference manual says:

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

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