Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb4b9f7

Browse files
tacaswelljankatins
authored andcommitted
MNT: add python 3 version of sig parsing
1 parent 7a6d44d commit bb4b9f7

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

lib/matplotlib/__init__.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,13 +1587,23 @@ def foo(ax, *args, **kwargs)
15871587
replace_names = set(replace_names)
15881588

15891589
def param(func):
1590-
# this call is deprecated in 3.x and will be removed in py3.6 :-(
1591-
# TODO: implement the same for py 3.x/3.6+ with inspect.signature(..)
1592-
arg_spec = inspect.getargspec(func)
1593-
_arg_names = arg_spec.args
1594-
_has_no_varargs = arg_spec.varargs is None
1595-
_has_varkwargs = arg_spec.keywords is not None
1596-
1590+
if six.PY2:
1591+
arg_spec = inspect.getargspec(func)
1592+
_arg_names = arg_spec.args
1593+
_has_no_varargs = arg_spec.varargs is None
1594+
_has_varkwargs = arg_spec.keywords is not None
1595+
elif six.PY3:
1596+
sig = inspect.signature(func)
1597+
_has_no_varargs = True
1598+
_has_varkwargs = False
1599+
_arg_names = []
1600+
for p in sig.parameters.values():
1601+
if p.kind is p.VAR_POSITIONAL:
1602+
_has_no_varargs = False
1603+
elif p.kind is p.VAR_KEYWORD:
1604+
_has_varkwargs = True
1605+
else:
1606+
_arg_names.append(p.name)
15971607
# Import-time check: do we have enough information to replace *args?
15981608
arg_names_at_runtime = False
15991609
# there can't be any positional arguments behind *args and no

0 commit comments

Comments
 (0)