Skip to content

Commit 5758ba0

Browse files
committed
Fix #81: Stop using 'inspect.getargspec()'
This function is deprecated and raises the warning. DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead While this suggests we use 'inspect.signature()', there's no reason to use this instead of the 'inspect.getfullargspec()', which has almost identical semantics to 'inspect.getargspec()' but handles kwargs-only functions. For what we want though, this is a drop-in replacement. Note that because 'inspect.getfullargspec()' isn't provided in Python 2.7, we may see slightly different behavior between Python 2 and 3 (e.g. for the kwargs-only case above). There's nothing we can do about this without vendoring the entire function. Signed-off-by: Stephen Finucane <[email protected]>
1 parent 4fb708b commit 5758ba0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pluggy/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ def varnames(func):
491491
return ()
492492

493493
try: # func MUST be a function or method here or we won't parse any args
494-
spec = inspect.getargspec(func)
494+
spec = _getargspec(func)
495495
except TypeError:
496496
return (), ()
497497

@@ -659,6 +659,14 @@ def __init__(self, plugin, plugin_name, function, hook_impl_opts):
659659
self.__dict__.update(hook_impl_opts)
660660

661661

662+
if hasattr(inspect, 'getfullargspec'):
663+
def _getargspec(func):
664+
return inspect.getfullargspec(func)
665+
else:
666+
def _getargspec(func):
667+
return inspect.getargspec(func)
668+
669+
662670
if hasattr(inspect, 'signature'):
663671
def _formatdef(func):
664672
return "%s%s" % (

tox.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ addopts=-rxsX
3939
norecursedirs=.tox ja .hg .env*
4040
filterwarnings =
4141
error
42-
# inspect.getargspec() ignored, should be fixed in #81
43-
ignore:inspect.getargspec().*deprecated
4442

4543
[flake8]
4644
max-line-length=99

0 commit comments

Comments
 (0)