[Python-checkins] python/dist/src/Doc/ref ref7.tex,1.38,1.39
anthonybaxter at users.sourceforge.net
anthonybaxter at users.sourceforge.net
Mon Aug 2 08:10:25 CEST 2004
Update of /cvsroot/python/python/dist/src/Doc/ref
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6086/Doc/ref
Modified Files:
ref7.tex
Log Message:
PEP-0318, @decorator-style. In Guido's words:
"@ seems the syntax that everybody can hate equally"
Implementation by Mark Russell, from SF #979728.
Index: ref7.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/ref/ref7.tex,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** ref7.tex 2 Jun 2004 12:59:59 -0000 1.38
--- ref7.tex 2 Aug 2004 06:09:52 -0000 1.39
***************
*** 316,321 ****
\begin{productionlist}
\production{funcdef}
! {"def" \token{funcname} "(" [\token{parameter_list}] ")"
":" \token{suite}}
\production{parameter_list}
{(\token{defparameter} ",")*}
--- 316,325 ----
\begin{productionlist}
\production{funcdef}
! {[\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} ",")*}
***************
*** 344,347 ****
--- 348,372 ----
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
More information about the Python-checkins
mailing list