Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9935e7f

Browse files
author
Skip Montanaro
committed
correct decorator example, tweak description slightly
1 parent 2eba0d6 commit 9935e7f

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

Doc/whatsnew/whatsnew24.tex

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ \section{PEP 318: Decorators for Functions and Methods}
289289
the following:
290290

291291
\begin{verbatim}
292-
@A @B @C
292+
@A
293+
@B
294+
@C
293295
def f ():
294296
...
295297
\end{verbatim}
@@ -301,16 +303,18 @@ \section{PEP 318: Decorators for Functions and Methods}
301303
f = A(B(C(f)))
302304
\end{verbatim}
303305

304-
Decorators must come on the line before a function definition, and
305-
can't be on the same line, meaning that \code{@A def f(): ...} is
306-
illegal. You can only decorate function definitions, either at the
307-
module level or inside a class; you can't decorate class definitions.
308-
309-
A decorator is just a function that takes the function to be decorated
310-
as an argument and returns either the same function or some new
311-
callable thing. It's easy to write your own decorators. The
312-
following simple example just sets an attribute on the function
313-
object:
306+
Decorators must come on the line before a function definition, one decorator
307+
per line, and can't be on the same line as the def statement, meaning that
308+
\code{@A def f(): ...} is illegal. You can only decorate function
309+
definitions, either at the module level or inside a class; you can't
310+
decorate class definitions.
311+
312+
A decorator is just a function that takes the function to be decorated as an
313+
argument and returns either the same function or some new object. The
314+
return value of the decorator need not be callable (though it typically is),
315+
unless further decorators will be applied to the result. It's easy to write
316+
your own decorators. The following simple example just sets an attribute on
317+
the function object:
314318

315319
\begin{verbatim}
316320
>>> def deco(func):

0 commit comments

Comments
 (0)