diff options
author | Michele Simionato <michele.simionato@gmail.com> | 2021-04-14 06:11:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-14 06:11:11 +0200 |
commit | e3c07ea54b6ea08765f01f72042debc66159d0a3 (patch) | |
tree | de4e57028e65df439c7a69d5893b710a2e949a05 | |
parent | d1b9cc4dfbb6425f1eef2cec3222027a718b9309 (diff) | |
parent | 187ef55dda5904505b669361e4f86f4f8b74b9e3 (diff) | |
download | python-decorator-git-e3c07ea54b6ea08765f01f72042debc66159d0a3.tar.gz |
Merge pull request #121 from micheles/apply_defaults
Restored apply_defaults
-rw-r--r-- | CHANGES.md | 7 | ||||
-rw-r--r-- | docs/documentation.md | 12 | ||||
-rw-r--r-- | src/decorator.py | 3 | ||||
-rw-r--r-- | src/tests/test.py | 20 |
4 files changed, 33 insertions, 9 deletions
@@ -3,6 +3,13 @@ HISTORY ## unreleased +## 5.0.7 (2021-04-14) + +The decorator module was not passing correctly the defaults inside the +`*args` tuple, thanks to Dan Shult for the fix. Also fixed some mispellings +in the documentation and integrated codespell in the CI, thanks to +Christian Clauss. + ## 5.0.6 (2021-04-08) The decorator module was not copying the __module__ attribute anymore. Thanks to diff --git a/docs/documentation.md b/docs/documentation.md index bc73dbe..7d8fede 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.6 (2021-04-10)| +|Version| 5.0.7 (2021-04-14)| |Supports| Python 3.5, 3.6, 3.7, 3.8, 3.9| -|Download page| http://pypi.python.org/pypi/decorator/5.0.6| +|Download page| http://pypi.python.org/pypi/decorator/5.0.7| |Installation| ``pip install decorator``| |License | BSD license| @@ -480,7 +480,7 @@ An example will make the issue clear. Here is a simple caller ```python def chatty(func, *args, **kwargs): - print(args, kwargs) + print(args, sorted(kwargs.items())) return func(*args, **kwargs) ``` @@ -500,7 +500,7 @@ tuple and not inside the ``kwargs`` dictionary: ```python >>> printsum(y=2, x=1) -(1, 2) {} +(1, 2) [] 3 ``` @@ -534,7 +534,7 @@ Here is how it works: ```python >>> printsum2(y=2, x=1) -() {'y': 2, 'x': 1} +() [('x', 1), ('y', 2)] 3 ``` @@ -546,7 +546,7 @@ positional, i.e. they belongs to the ``args`` tuple and not to ``kwargs``: ```python >>> printsum2(1, 2) -(1, 2) {} +(1, 2) [] 3 ``` diff --git a/src/decorator.py b/src/decorator.py index deb93cd..d8db26d 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.6' +__version__ = '5.0.7' DEF = re.compile(r'\s*def\s*([_\w][_\w\d]*)\s*\(') POS = inspect.Parameter.POSITIONAL_OR_KEYWORD @@ -201,6 +201,7 @@ def fix(args, kwargs, sig): Fix args and kwargs to be consistent with the signature """ ba = sig.bind(*args, **kwargs) + ba.apply_defaults() # needed for test_dan_schult return ba.args, ba.kwargs diff --git a/src/tests/test.py b/src/tests/test.py index c10757d..acdaf93 100644 --- a/src/tests/test.py +++ b/src/tests/test.py @@ -6,7 +6,10 @@ import inspect from asyncio import get_event_loop from collections import defaultdict, ChainMap, abc as c from decorator import dispatch_on, contextmanager, decorator -import documentation as doc +try: + from . import documentation as doc # good with pytest +except ImportError: + import documentation as doc # good with `python src/tests/test.py` @contextmanager @@ -71,7 +74,7 @@ class DocumentationTestCase(unittest.TestCase): def test_copy_dunder_attrs(self): traced = doc.trace(doc.foo) - self.assertEqual(traced.__module__, 'documentation') + self.assertIn('documentation', traced.__module__) self.assertEqual(traced.__annotations__, {}) self.assertEqual(traced.__defaults__, (None,)) @@ -167,6 +170,19 @@ class ExtraTestCase(unittest.TestCase): return x self.assertEqual(add(f, 2)(0), 2) + def test_dan_schult(self): + # see https://github.com/micheles/decorator/issues/120 + @decorator + def prnt(func, index=0, *args, **kw): + print(args[index]) + return func(*args, **kw) + + @prnt(index=2) # print the value of the third argument + def f(a, b, c=None): + return [a, b, c] + + self.assertEqual(f(0, 1), [0, 1, None]) + # ################### test dispatch_on ############################# # # adapted from test_functools in Python 3.5 |