From f5dc018b7d73c77c995c07a2ddde26b164fc71c7 Mon Sep 17 00:00:00 2001 From: Michele Simionato Date: Wed, 22 Jul 2015 11:14:41 +0200 Subject: Added a note about __qualname__ --- src/tests/documentation.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/tests/documentation.py') diff --git a/src/tests/documentation.py b/src/tests/documentation.py index e4d99b6..8282063 100644 --- a/src/tests/documentation.py +++ b/src/tests/documentation.py @@ -591,9 +591,11 @@ having to rewrite them in terms of ``decorator``. You can use a $$decorator_apply -``decorator_apply`` sets the attribute ``.__wrapped__`` of the generated +``decorator_apply`` sets the attribute ``__wrapped__`` of the generated function to the original function, so that you can get the right -source code. +source code. If you are using Python 3, you should also set the +``__qualname__`` attribute to preserve the qualified name of the +original function. Notice that I am not providing this functionality in the ``decorator`` module directly since I think it is best to rewrite the decorator rather @@ -1053,9 +1055,9 @@ You can check that the ``__annotations__`` dictionary is preserved: True Here ``f.__wrapped__`` is the original undecorated function. Such an attribute -is added to be consistent with the way `functools.update_wrapper` work. +is added to be consistent with the way ``functools.update_wrapper`` work. Another attribute which is copied from the original function is -`__qualname`, the qualified name. This is a concept introduced +``__qualname__``, the qualified name. This is a concept introduced in Python 3. In Python 2 the decorator module will still add a qualified name, but its value will always be `None`. """ @@ -1084,8 +1086,8 @@ def decorator_apply(dec, func): is not a signature-preserving decorator. """ return FunctionMaker.create( - func, 'return decorated(%(signature)s)', - dict(decorated=dec(func)), __wrapped__=func) + func, 'return decfunc(%(signature)s)', + dict(decfunc=dec(func)), __wrapped__=func) def _trace(f, *args, **kw): -- cgit v1.2.1