From 5758ba098b670604c94d709d507d51ceaf0d94e4 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Sun, 29 Oct 2017 14:49:00 +0000 Subject: [PATCH] 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 --- pluggy/__init__.py | 10 +++++++++- tox.ini | 2 -- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pluggy/__init__.py b/pluggy/__init__.py index 46011b8e..40dd02f9 100644 --- a/pluggy/__init__.py +++ b/pluggy/__init__.py @@ -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 (), () @@ -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" % ( diff --git a/tox.ini b/tox.ini index 2acf6835..c7a3587c 100644 --- a/tox.ini +++ b/tox.ini @@ -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