This is Mark Russell's patch:
[ 1009560 ] Fix @decorator evaluation order
From the description:
Changes in this patch:
- Change Grammar/Grammar to require
newlines between adjacent decorators.
- Fix order of evaluation of decorators
in the C (compile.c) and python
(Lib/compiler/pycodegen.py) compilers
- Add better order of evaluation check
to test_decorators.py (test_eval_order)
- Update the decorator documentation in
the reference manual (improve description
of evaluation order and update syntax
description)
and the comment:
Used Brett's evaluation order (see
http://mail.python.org/pipermail/python-dev/2004-August/047835.html)
(I'm checking this in for Anthony who was having problems getting SF to
talk to him)
diff --git a/Doc/ref/ref7.tex b/Doc/ref/ref7.tex
index 1d7b860..88c548c 100644
--- a/Doc/ref/ref7.tex
+++ b/Doc/ref/ref7.tex
@@ -318,9 +318,9 @@
{[\token{decorators}] "def" \token{funcname} "(" [\token{parameter_list}] ")"
":" \token{suite}}
\production{decorators}
- {\token{decorator} ([NEWLINE] \token{decorator})* NEWLINE}
+ {\token{decorator}+}
\production{decorator}
- {"@" \token{dotted_name} ["(" [\token{argument_list} [","]] ")"]}
+ {"@" \token{dotted_name} ["(" [\token{argument_list} [","]] ")"] NEWLINE}
\production{parameter_list}
{(\token{defparameter} ",")*}
\productioncont{("*" \token{identifier} [, "**" \token{identifier}]}
@@ -352,11 +352,11 @@
that contains the function definition. The result must be a callable,
which is invoked with the function object as the only argument.
The returned value is bound to the function name instead of the function
-object. If there are multiple decorators, they are applied in reverse
-order. For example, the following code:
+object. Multiple decorators are applied in nested fashion.
+For example, the following code:
\begin{verbatim}
-@f1
+@f1(arg)
@f2
def func(): pass
\end{verbatim}
@@ -365,7 +365,7 @@
\begin{verbatim}
def func(): pass
-func = f2(f1(func))
+func = f1(arg)(f2(func))
\end{verbatim}
When one or more top-level parameters have the form \var{parameter}