mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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)
This commit is contained in:
parent
b51b23405b
commit
0ccff074cd
8 changed files with 142 additions and 96 deletions
|
@ -318,9 +318,9 @@ section~\ref{types}):
|
|||
{[\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 @@ Decorator expressions are evaluated when the function is defined, in the scope
|
|||
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 @@ is equivalent to:
|
|||
|
||||
\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}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue