diff --git a/CHANGES.md b/CHANGES.md index 111ad8d..3e9bd3f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,10 @@ HISTORY ## Unreleased +## 4.2.1 (2018-01-14) + +Fixed a regression breaking IPython and discovered by https://github.com/spapini + ## 4.2.0 (2018-01-14) Added a facility to define families of decorators (aka decorators with diff --git a/docs/tests.documentation.rst b/docs/tests.documentation.rst index 92836e2..97f264c 100644 --- a/docs/tests.documentation.rst +++ b/docs/tests.documentation.rst @@ -3,9 +3,9 @@ The ``decorator`` module :Author: Michele Simionato :E-mail: michele.simionato@gmail.com -:Version: 4.2.0 (2018-01-14) +:Version: 4.2.1 (2018-01-14) :Supports: Python 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6 -:Download page: http://pypi.python.org/pypi/decorator/4.2.0 +:Download page: http://pypi.python.org/pypi/decorator/4.2.1 :Installation: ``pip install decorator`` :License: BSD license 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 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 @@ def func(**kw): # 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