diff options
author | Michele Simionato <michele.simionato@gmail.com> | 2021-04-08 07:45:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-08 07:45:24 +0200 |
commit | 949e8e0dbc251f3aa30546761f5dc220822d6e7e (patch) | |
tree | c59244a6bb0d4c31a18e26242f95630e87aedc5f | |
parent | fb8a321d672848852d7706b3c40156771e568084 (diff) | |
parent | b2e77f281365007b756626372fb234c13f9426bb (diff) | |
download | python-decorator-git-949e8e0dbc251f3aa30546761f5dc220822d6e7e.tar.gz |
Merge pull request #113 from micheles/__module__
func.__module__ was not copied anymore
-rw-r--r-- | CHANGES.md | 5 | ||||
-rw-r--r-- | docs/documentation.md | 4 | ||||
-rw-r--r-- | src/decorator.py | 10 | ||||
-rw-r--r-- | src/tests/documentation.py | 7 | ||||
-rw-r--r-- | src/tests/test.py | 6 |
5 files changed, 22 insertions, 10 deletions
@@ -3,6 +3,11 @@ HISTORY ## unreleased +## 5.0.6 (2021-04-08) + +The decorator module was not copying the __module__ attribute anymore. Thanks to +Nikolay Markov for the notice. + ## 5.0.5 (2021-04-04) Dropped support for Python < 3.5 with a substantial simplification of diff --git a/docs/documentation.md b/docs/documentation.md index b3747a9..ba5a99c 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -4,9 +4,9 @@ Decorators for Humans |Author | Michele Simionato| |---|---| |E-mail | michele.simionato@gmail.com| -|Version| 5.0.5 (2021-04-04)| +|Version| 5.0.6 (2021-04-08)| |Supports| Python 3.5, 3.6, 3.7, 3.8, 3.9| -|Download page| http://pypi.python.org/pypi/decorator/5.0.5| +|Download page| http://pypi.python.org/pypi/decorator/5.0.6| |Installation| ``pip install decorator``| |License | BSD license| diff --git a/src/decorator.py b/src/decorator.py index aa406cb..deb93cd 100644 --- a/src/decorator.py +++ b/src/decorator.py @@ -40,7 +40,7 @@ import itertools from contextlib import _GeneratorContextManager from inspect import getfullargspec, iscoroutinefunction, isgeneratorfunction -__version__ = '5.0.5' +__version__ = '5.0.6' DEF = re.compile(r'\s*def\s*([_\w][_\w\d]*)\s*\(') POS = inspect.Parameter.POSITIONAL_OR_KEYWORD @@ -230,12 +230,14 @@ def decorate(func, caller, extras=(), kwsyntax=False): args, kw = fix(args, kw, sig) return caller(func, *(extras + args), **kw) fun.__name__ = func.__name__ + fun.__doc__ = func.__doc__ + fun.__defaults__ = func.__defaults__ + fun.__kwdefaults__ = func.__kwdefaults__ + fun.__annotations__ = func.__annotations__ + fun.__module__ = func.__module__ fun.__signature__ = sig fun.__wrapped__ = func fun.__qualname__ = func.__qualname__ - fun.__annotations__ = func.__annotations__ - fun.__kwdefaults__ = func.__kwdefaults__ - fun.__doc__ = func.__doc__ fun.__dict__.update(func.__dict__) return fun diff --git a/src/tests/documentation.py b/src/tests/documentation.py index 40b0a28..3ddc6a1 100644 --- a/src/tests/documentation.py +++ b/src/tests/documentation.py @@ -1852,14 +1852,13 @@ def to_method(f): self = inspect.Parameter('self', inspect.Parameter.POSITIONAL_OR_KEYWORD) params.insert(0, self) # insert self del params[-1] # remove context - newsig = sig.replace(parameters=params) + newsig = '%s%s' % (f.__name__, sig.replace(parameters=params)) return FunctionMaker.create( - '%s%s' % (f.__name__, newsig), - 'context = self.context; return _func_%s' % sig, + newsig, 'context = self.context; return _func_%s' % sig, dict(_func_=f)) -def foo(x, context): +def foo(x, context=None): return x diff --git a/src/tests/test.py b/src/tests/test.py index ad45ca1..c10757d 100644 --- a/src/tests/test.py +++ b/src/tests/test.py @@ -69,6 +69,12 @@ class DocumentationTestCase(unittest.TestCase): err = doctest.testmod(doc)[0] self.assertEqual(err, 0) + def test_copy_dunder_attrs(self): + traced = doc.trace(doc.foo) + self.assertEqual(traced.__module__, 'documentation') + self.assertEqual(traced.__annotations__, {}) + self.assertEqual(traced.__defaults__, (None,)) + def test_singledispatch1(self): with assertRaises(RuntimeError): doc.singledispatch_example1() |