summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichele Simionato <michele.simionato@gmail.com>2021-04-14 06:09:12 +0200
committerMichele Simionato <michele.simionato@gmail.com>2021-04-14 06:09:12 +0200
commit187ef55dda5904505b669361e4f86f4f8b74b9e3 (patch)
treed056eca4c9dd1ba438fdbf0f3b37bd6b1dae731d /src
parentc8fed191b3133bdb3021c531e5cc9dada1953a7d (diff)
downloadpython-decorator-git-187ef55dda5904505b669361e4f86f4f8b74b9e3.tar.gz
Restored apply_defaults
Diffstat (limited to 'src')
-rw-r--r--src/decorator.py3
-rw-r--r--src/tests/test.py20
2 files changed, 20 insertions, 3 deletions
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