Skip to content

Commit

Permalink
Fix #81: Stop using 'inspect.getargspec()'
Browse files Browse the repository at this point in the history
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 <stephen@that.guru>
  • Loading branch information
stephenfin committed Oct 29, 2017
1 parent 4fb708b commit 5758ba0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pluggy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def varnames(func):
return ()

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

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


if hasattr(inspect, 'getfullargspec'):
def _getargspec(func):
return inspect.getfullargspec(func)
else:
def _getargspec(func):
return inspect.getargspec(func)


if hasattr(inspect, 'signature'):
def _formatdef(func):
return "%s%s" % (
Expand Down
2 changes: 0 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ addopts=-rxsX
norecursedirs=.tox ja .hg .env*
filterwarnings =
error
# inspect.getargspec() ignored, should be fixed in #81
ignore:inspect.getargspec().*deprecated

[flake8]
max-line-length=99

0 comments on commit 5758ba0

Please sign in to comment.