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

Skip to content

Commit 9c1199b

Browse files
tacaswelljankatins
authored andcommitted
ENH: add 'data' to signature in python 3.3 +
- Properly check that inspect has the signature (keeps 3.0-3.2 nominally working) by checking version numbers
1 parent bb4b9f7 commit 9c1199b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/matplotlib/__init__.py

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

15891589
def param(func):
1590-
if six.PY2:
1590+
new_sig = None
1591+
ver_info = sys.version_info
1592+
_python_has_signature = ver_info.major > 2 and ver_info.minor > 2
1593+
if not _python_has_signature:
15911594
arg_spec = inspect.getargspec(func)
15921595
_arg_names = arg_spec.args
15931596
_has_no_varargs = arg_spec.varargs is None
15941597
_has_varkwargs = arg_spec.keywords is not None
1595-
elif six.PY3:
1598+
else:
15961599
sig = inspect.signature(func)
15971600
_has_no_varargs = True
15981601
_has_varkwargs = False
15991602
_arg_names = []
1600-
for p in sig.parameters.values():
1603+
params = list(sig.parameters.values())
1604+
for p in params:
16011605
if p.kind is p.VAR_POSITIONAL:
16021606
_has_no_varargs = False
16031607
elif p.kind is p.VAR_KEYWORD:
16041608
_has_varkwargs = True
16051609
else:
16061610
_arg_names.append(p.name)
1611+
data_param = inspect.Parameter('data',
1612+
inspect.Parameter.KEYWORD_ONLY,
1613+
default=None)
1614+
if _has_varkwargs:
1615+
params.insert(-1, data_param)
1616+
else:
1617+
params.append(data_param)
1618+
new_sig = sig.replace(parameters=params)
16071619
# Import-time check: do we have enough information to replace *args?
16081620
arg_names_at_runtime = False
16091621
# there can't be any positional arguments behind *args and no
@@ -1777,6 +1789,8 @@ def inner(ax, *args, **kwargs):
17771789
_repl = _repl.format(names="', '".join(replace_names))
17781790
inner.__doc__ = (pre_doc +
17791791
_DATA_DOC_APPENDIX.format(replaced=_repl))
1792+
if new_sig is not None:
1793+
inner.__signature__ = new_sig
17801794
return inner
17811795
return param
17821796

0 commit comments

Comments
 (0)