summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/decorator.py5
-rw-r--r--src/tests/test.py6
2 files changed, 9 insertions, 2 deletions
diff --git a/src/decorator.py b/src/decorator.py
index 9f4eb2b..6e5db6f 100644
--- a/src/decorator.py
+++ b/src/decorator.py
@@ -40,7 +40,7 @@ import operator
import itertools
import collections
-__version__ = '4.2.0'
+__version__ = '4.2.1'
if sys.version >= '3':
from inspect import getfullargspec
@@ -261,7 +261,8 @@ def decorator(caller, _func=None):
name = caller.__name__
doc = caller.__doc__
nargs = caller.__code__.co_argcount
- defaultargs = ', '.join(caller.__code__.co_varnames[1:nargs])
+ ndefs = len(caller.__defaults__ or ())
+ defaultargs = ', '.join(caller.__code__.co_varnames[nargs-ndefs:nargs])
if defaultargs:
defaultargs += ','
defaults = caller.__defaults__
diff --git a/src/tests/test.py b/src/tests/test.py
index 7eb8391..e5f2ff4 100644
--- a/src/tests/test.py
+++ b/src/tests/test.py
@@ -119,6 +119,12 @@ class ExtraTestCase(unittest.TestCase):
# there is no confusion when passing args as a keyword argument
self.assertEqual(func(args='a'), {'args': 'a'})
+ def test_decorator_factory(self):
+ # similar to what IPython is doing in traitlets.config.application
+ @decorator
+ def catch_config_error(method, app, *args, **kwargs):
+ return method(app)
+ catch_config_error(lambda app: None)
# ################### test dispatch_on ############################# #
# adapted from test_functools in Python 3.5