[Python-Dev] Decorator order implemented backwards?

Michael Chermside mcherm at mcherm.com
Tue Aug 17 18:40:02 CEST 2004


Mark writes:
> Your patch results in the evaluation order:
>
>     evalname1 evalargs1 makedec1
>     evalname2 evalargs2 makedec2
>     evalname3 evalargs3 makedec3
>     calldec3 calldec2 calldec1
>
> Mine (#1009560) gives:
>
>     evalname3 evalargs3 makedec3 calldec3
>     evalname2 evalargs2 makedec2 calldec2
>     evalname1 evalargs1 makedec1 calldec1

Guido writes:
> Since Mark ended up agreeing with your order, the OK is given by
> default. :-)

Wait... I'm confused. What was the final decision? I favor

     evalname1 evalargs1 makedec1
     evalname2 evalargs2 makedec2
     evalname3 evalargs3 makedec3
     calldec3 calldec2 calldec1

becase of left-to-right-top-to-bottom evaluation. Is this what it
actually does? I imagine this:

      >>> # Warning - not actual code
      >>> def dummyDecorator1(x):
      ...     print 'one'
      ...     return x
      ...
      >>> def dummyDecorator2(x):
      ...     print 'two'
      ...     return x
      ...
      >>> @dummyDecorator1
      >>> @dummyDecorator2
      >>> def func(): pass
      two
      one

which somehow seems wrong to me.

-- Michael Chermside



More information about the Python-Dev mailing list