[Python-Dev] order of decorator application?

ncoghlan at iinet.net.au ncoghlan at iinet.net.au
Wed Mar 24 09:12:37 EST 2004


Quoting "Phillip J. Eby" <pje at telecommunity.com>:

> At 10:24 AM 3/23/04 -0600, Skip Montanaro wrote:
> 
> >(I'm working on PEP 318...)
> >
> >
> >     def func(a,b):
> >         pass
> >     func = d2(d1(func))
> 

Another phrasing which makes L2R the 'obvious' evaluation order - don't nest 
the functions when spelling out the long form (i.e. unrolling Phillip's loop):
  def func(a,b):
    pass
  func = d1(func)
  func = d2(func)

The only way the issue is ever confused is when all the decorators are applied 
on the one line in the 'long spelling', in which case the nesting inverts the 
order of the functions. So if we refrain from ever doing that in the official 
documentation, there isn't likely to be as much confusion over the ordering.

Regards,
Nick.




More information about the Python-Dev mailing list