Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
57e62c74
Commit
57e62c74
authored
Dec 26, 2004
by
Skip Montanaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct decorator example, tweak description slightly
parent
5378aaae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
11 deletions
+15
-11
Doc/whatsnew/whatsnew24.tex
Doc/whatsnew/whatsnew24.tex
+15
-11
No files found.
Doc/whatsnew/whatsnew24.tex
View file @
57e62c74
...
...
@@ -289,7 +289,9 @@ The \code{@classmethod} is shorthand for the
the following:
\begin
{
verbatim
}
@A @B @C
@A
@B
@C
def f
()
:
...
\end
{
verbatim
}
...
...
@@ -301,16 +303,18 @@ def f(): ...
f
=
A
(
B
(
C
(
f
)))
\end
{
verbatim
}
Decorators must come on the line before a function definition, and
can't be on the same line, meaning that
\code
{
@A def f
()
: ...
}
is
illegal. You can only decorate function definitions, either at the
module level or inside a class; you can't decorate class definitions.
A decorator is just a function that takes the function to be decorated
as an argument and returns either the same function or some new
callable thing. It's easy to write your own decorators. The
following simple example just sets an attribute on the function
object:
Decorators must come on the line before a function definition, one decorator
per line, and can't be on the same line as the def statement, meaning that
\code
{
@A def f
()
: ...
}
is illegal. You can only decorate function
definitions, either at the module level or inside a class; you can't
decorate class definitions.
A decorator is just a function that takes the function to be decorated as an
argument and returns either the same function or some new object. The
return value of the decorator need not be callable
(
though it typically is
)
,
unless further decorators will be applied to the result. It's easy to write
your own decorators. The following simple example just sets an attribute on
the function object:
\begin
{
verbatim
}
>>> def deco
(
func
)
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment