diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/decorator.py | 8 | ||||
| -rw-r--r-- | src/tests/documentation.py | 5 | ||||
| -rw-r--r-- | src/tests/test.py | 7 |
3 files changed, 14 insertions, 6 deletions
diff --git a/src/decorator.py b/src/decorator.py index 8faee1f..4369462 100644 --- a/src/decorator.py +++ b/src/decorator.py @@ -219,10 +219,12 @@ def decorate(func, caller): evaldict = func.__globals__.copy() evaldict['_call_'] = caller evaldict['_func_'] = func - qn = getattr(func, '__qualname__', None) - return FunctionMaker.create( + fun = FunctionMaker.create( func, "return _call_(_func_, %(shortsignature)s)", - evaldict, __wrapped__=func, __qualname__=qn) + evaldict, __wrapped__=func) + if hasattr(func, '__qualname__'): + fun.__qualname__ = func.__qualname__ + return fun def decorator(caller, _func=None): diff --git a/src/tests/documentation.py b/src/tests/documentation.py index e82ba8e..350f05c 100644 --- a/src/tests/documentation.py +++ b/src/tests/documentation.py @@ -1121,9 +1121,8 @@ You can check that the ``__annotations__`` dictionary is preserved: Here ``f.__wrapped__`` is the original undecorated function. Such an attribute 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 -in Python 3. In Python 2 the decorator module will still add a -qualified name, but its value will always be ``None``. +``__qualname__``, the qualified name. This is an attribute which is +present only in Python 3. """ import sys diff --git a/src/tests/test.py b/src/tests/test.py index 951958c..9428fa9 100644 --- a/src/tests/test.py +++ b/src/tests/test.py @@ -40,6 +40,13 @@ class DocumentationTestCase(unittest.TestCase): class ExtraTestCase(unittest.TestCase): + def test_qualname(self): + if sys.version >= '3': + self.assertEqual(doc.hello.__qualname__, 'hello') + else: + with assertRaises(AttributeError): + doc.hello.__qualname__ + def test_signature(self): if hasattr(inspect, 'signature'): sig = inspect.signature(doc.f1) |
