diff options
author | Anthony Baxter <anthonybaxter@gmail.com> | 2004-08-02 06:10:11 (GMT) |
---|---|---|
committer | Anthony Baxter <anthonybaxter@gmail.com> | 2004-08-02 06:10:11 (GMT) |
commit | c2a5a636545a88f349dbe3e452ffb4494b68e534 (patch) | |
tree | aaa24074dcdcce5afa51523969971bdd05381b01 /Doc/ref | |
parent | fd7dc5169c3ca7d64109512f38762c4ce9e96c5f (diff) | |
download | cpython-c2a5a636545a88f349dbe3e452ffb4494b68e534.zip cpython-c2a5a636545a88f349dbe3e452ffb4494b68e534.tar.gz cpython-c2a5a636545a88f349dbe3e452ffb4494b68e534.tar.bz2 |
PEP-0318, @decorator-style. In Guido's words:
"@ seems the syntax that everybody can hate equally"
Implementation by Mark Russell, from SF #979728.
Diffstat (limited to 'Doc/ref')
-rw-r--r-- | Doc/ref/ref7.tex | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/Doc/ref/ref7.tex b/Doc/ref/ref7.tex index 80ddc33..1d7b860 100644 --- a/Doc/ref/ref7.tex +++ b/Doc/ref/ref7.tex @@ -315,8 +315,12 @@ section~\ref{types}): \begin{productionlist} \production{funcdef} - {"def" \token{funcname} "(" [\token{parameter_list}] ")" + {[\token{decorators}] "def" \token{funcname} "(" [\token{parameter_list}] ")" ":" \token{suite}} + \production{decorators} + {\token{decorator} ([NEWLINE] \token{decorator})* NEWLINE} + \production{decorator} + {"@" \token{dotted_name} ["(" [\token{argument_list} [","]] ")"]} \production{parameter_list} {(\token{defparameter} ",")*} \productioncont{("*" \token{identifier} [, "**" \token{identifier}]} @@ -343,6 +347,27 @@ as the global namespace to be used when the function is called. The function definition does not execute the function body; this gets executed only when the function is called. +A function definition may be wrapped by one or more decorator expressions. +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: + +\begin{verbatim} +@f1 +@f2 +def func(): pass +\end{verbatim} + +is equivalent to: + +\begin{verbatim} +def func(): pass +func = f2(f1(func)) +\end{verbatim} + When one or more top-level parameters have the form \var{parameter} \code{=} \var{expression}, the function is said to have ``default parameter values.'' For a parameter with a |