summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-02-15 10:38:03 +0000
committerGeorg Brandl <georg@python.org>2007-02-15 10:38:03 +0000
commitd2bf6c0a062031e4224f6b517da0554c770fd156 (patch)
tree3dcdd83cc890ff5a56f5488d5b29b9bb86e6801d
parentd1a29c5dee2d052640661b768af672fd118d0b2c (diff)
downloadcpython-git-d2bf6c0a062031e4224f6b517da0554c770fd156.tar.gz
Make functools.wraps() docs a bit clearer.
(backport from rev. 53783)
-rw-r--r--Doc/lib/libfunctools.tex17
1 files changed, 11 insertions, 6 deletions
diff --git a/Doc/lib/libfunctools.tex b/Doc/lib/libfunctools.tex
index 33a6f52964..9404fca363 100644
--- a/Doc/lib/libfunctools.tex
+++ b/Doc/lib/libfunctools.tex
@@ -53,15 +53,16 @@ two:
\begin{funcdesc}{update_wrapper}
{wrapper, wrapped\optional{, assigned}\optional{, updated}}
-Update a wrapper function to look like the wrapped function. The optional
-arguments are tuples to specify which attributes of the original
+Update a \var{wrapper} function to look like the \var{wrapped} function.
+The optional arguments are tuples to specify which attributes of the original
function are assigned directly to the matching attributes on the wrapper
function and which attributes of the wrapper function are updated with
the corresponding attributes from the original function. The default
values for these arguments are the module level constants
-\var{WRAPPER_ASSIGNMENTS} (which assigns to the wrapper function's name,
-module and documentation string) and \var{WRAPPER_UPDATES} (which
-updates the wrapper function's instance dictionary).
+\var{WRAPPER_ASSIGNMENTS} (which assigns to the wrapper function's
+\var{__name__}, \var{__module__} and \var{__doc__}, the documentation string)
+and \var{WRAPPER_UPDATES} (which updates the wrapper function's \var{__dict__},
+i.e. the instance dictionary).
The main intended use for this function is in decorator functions
which wrap the decorated function and return the wrapper. If the
@@ -85,6 +86,7 @@ as a function decorator when defining a wrapper function. For example:
...
>>> @my_decorator
... def example():
+ ... """Docstring"""
... print 'Called example function'
...
>>> example()
@@ -92,9 +94,12 @@ as a function decorator when defining a wrapper function. For example:
Called example function
>>> example.__name__
'example'
+ >>> example.__doc__
+ 'Docstring'
\end{verbatim}
Without the use of this decorator factory, the name of the example
-function would have been \code{'wrapper'}.
+function would have been \code{'wrapper'}, and the docstring of the
+original \function{example()} would have been lost.
\end{funcdesc}