1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-21 07:52:49 +00:00

Use getfullargspec under the scenes for py3 to stop DeprecationWarning (#2864)

Use getfullargspec under the scenes for py3 to stop DeprecationWarning. 

Closes #2862
This commit is contained in:
Andrei Petre 2017-08-01 17:14:43 +03:00 committed by Daniel Graña
parent 19382c5675
commit 6e6b5cc29f

View File

@ -10,7 +10,6 @@ import errno
import six
from functools import partial, wraps
import sys
import time
from scrapy.utils.decorators import deprecated
@ -198,10 +197,30 @@ def binary_is_text(data):
return all(c not in _BINARYCHARS for c in data)
def _getargspec_py23(func):
"""_getargspec_py23(function) -> named tuple ArgSpec(args, varargs, keywords,
defaults)
Identical to inspect.getargspec() in python2, but uses
inspect.getfullargspec() for python3 behind the scenes to avoid
DeprecationWarning.
>>> def f(a, b=2, *ar, **kw):
... pass
>>> _getargspec_py23(f)
ArgSpec(args=['a', 'b'], varargs='ar', keywords='kw', defaults=(2,))
"""
if six.PY2:
return inspect.getargspec(func)
return inspect.ArgSpec(*inspect.getfullargspec(func)[:4])
def get_func_args(func, stripself=False):
"""Return the argument name list of a callable"""
if inspect.isfunction(func):
func_args, _, _, _ = inspect.getargspec(func)
func_args, _, _, _ = _getargspec_py23(func)
elif inspect.isclass(func):
return get_func_args(func.__init__, True)
elif inspect.ismethod(func):
@ -248,9 +267,9 @@ def get_spec(func):
"""
if inspect.isfunction(func) or inspect.ismethod(func):
spec = inspect.getargspec(func)
spec = _getargspec_py23(func)
elif hasattr(func, '__call__'):
spec = inspect.getargspec(func.__call__)
spec = _getargspec_py23(func.__call__)
else:
raise TypeError('%s is not callable' % type(func))