Commit aee19f54 authored by Pablo Galindo's avatar Pablo Galindo Committed by GitHub

bpo-36751: Undeprecate getfullargspec (GH-13245)

parent 54b43bb3
...@@ -948,11 +948,6 @@ Classes and functions ...@@ -948,11 +948,6 @@ Classes and functions
APIs. This function is retained primarily for use in code that needs to APIs. This function is retained primarily for use in code that needs to
maintain compatibility with the Python 2 ``inspect`` module API. maintain compatibility with the Python 2 ``inspect`` module API.
.. deprecated:: 3.8
Use :func:`signature` and
:ref:`Signature Object <inspect-signature-object>`, which provide a
better introspecting API for callables.
.. versionchanged:: 3.4 .. versionchanged:: 3.4
This function is now based on :func:`signature`, but still ignores This function is now based on :func:`signature`, but still ignores
``__wrapped__`` attributes and includes the already bound first ``__wrapped__`` attributes and includes the already bound first
......
...@@ -780,10 +780,6 @@ Deprecated ...@@ -780,10 +780,6 @@ Deprecated
<positional-only_parameter>`. <positional-only_parameter>`.
(Contributed by Serhiy Storchaka in :issue:`36492`.) (Contributed by Serhiy Storchaka in :issue:`36492`.)
* The function :func:`~inspect.getfullargspec` in the :mod:`inspect`
module is deprecated in favor of the :func:`inspect.signature`
API. (Contributed by Pablo Galindo in :issue:`36751`.)
API and Feature Removals API and Feature Removals
======================== ========================
......
...@@ -1103,16 +1103,10 @@ def getfullargspec(func): ...@@ -1103,16 +1103,10 @@ def getfullargspec(func):
'kwonlydefaults' is a dictionary mapping names from kwonlyargs to defaults. 'kwonlydefaults' is a dictionary mapping names from kwonlyargs to defaults.
'annotations' is a dictionary mapping parameter names to annotations. 'annotations' is a dictionary mapping parameter names to annotations.
.. deprecated:: 3.8
Use inspect.signature() instead of inspect.getfullargspec().
Notable differences from inspect.signature(): Notable differences from inspect.signature():
- the "self" parameter is always reported, even for bound methods - the "self" parameter is always reported, even for bound methods
- wrapper chains defined by __wrapped__ *not* unwrapped automatically - wrapper chains defined by __wrapped__ *not* unwrapped automatically
""" """
warnings.warn("Use inspect.signature() instead of inspect.getfullargspec()",
DeprecationWarning, stacklevel=2)
try: try:
# Re: `skip_bound_arg=False` # Re: `skip_bound_arg=False`
# #
......
...@@ -750,25 +750,22 @@ class TestClassesAndFunctions(unittest.TestCase): ...@@ -750,25 +750,22 @@ class TestClassesAndFunctions(unittest.TestCase):
def assertArgSpecEquals(self, routine, args_e, varargs_e=None, def assertArgSpecEquals(self, routine, args_e, varargs_e=None,
varkw_e=None, defaults_e=None, formatted=None): varkw_e=None, defaults_e=None, formatted=None):
with self.assertWarns(DeprecationWarning): args, varargs, varkw, defaults = inspect.getargspec(routine)
args, varargs, varkw, defaults = inspect.getargspec(routine)
self.assertEqual(args, args_e) self.assertEqual(args, args_e)
self.assertEqual(varargs, varargs_e) self.assertEqual(varargs, varargs_e)
self.assertEqual(varkw, varkw_e) self.assertEqual(varkw, varkw_e)
self.assertEqual(defaults, defaults_e) self.assertEqual(defaults, defaults_e)
if formatted is not None: if formatted is not None:
with self.assertWarns(DeprecationWarning): self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults),
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults), formatted)
formatted)
def assertFullArgSpecEquals(self, routine, args_e, varargs_e=None, def assertFullArgSpecEquals(self, routine, args_e, varargs_e=None,
varkw_e=None, defaults_e=None, varkw_e=None, defaults_e=None,
posonlyargs_e=[], kwonlyargs_e=[], posonlyargs_e=[], kwonlyargs_e=[],
kwonlydefaults_e=None, kwonlydefaults_e=None,
ann_e={}, formatted=None): ann_e={}, formatted=None):
with self.assertWarns(DeprecationWarning): args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \
args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \ inspect.getfullargspec(routine)
inspect.getfullargspec(routine)
self.assertEqual(args, args_e) self.assertEqual(args, args_e)
self.assertEqual(varargs, varargs_e) self.assertEqual(varargs, varargs_e)
self.assertEqual(varkw, varkw_e) self.assertEqual(varkw, varkw_e)
...@@ -777,9 +774,8 @@ class TestClassesAndFunctions(unittest.TestCase): ...@@ -777,9 +774,8 @@ class TestClassesAndFunctions(unittest.TestCase):
self.assertEqual(kwonlydefaults, kwonlydefaults_e) self.assertEqual(kwonlydefaults, kwonlydefaults_e)
self.assertEqual(ann, ann_e) self.assertEqual(ann, ann_e)
if formatted is not None: if formatted is not None:
with self.assertWarns(DeprecationWarning): self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults,
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann),
kwonlyargs, kwonlydefaults, ann),
formatted) formatted)
def test_getargspec(self): def test_getargspec(self):
...@@ -879,13 +875,11 @@ class TestClassesAndFunctions(unittest.TestCase): ...@@ -879,13 +875,11 @@ class TestClassesAndFunctions(unittest.TestCase):
def test_getfullargspec_signature_annos(self): def test_getfullargspec_signature_annos(self):
def test(a:'spam') -> 'ham': pass def test(a:'spam') -> 'ham': pass
with self.assertWarns(DeprecationWarning): spec = inspect.getfullargspec(test)
spec = inspect.getfullargspec(test)
self.assertEqual(test.__annotations__, spec.annotations) self.assertEqual(test.__annotations__, spec.annotations)
def test(): pass def test(): pass
with self.assertWarns(DeprecationWarning): spec = inspect.getfullargspec(test)
spec = inspect.getfullargspec(test)
self.assertEqual(test.__annotations__, spec.annotations) self.assertEqual(test.__annotations__, spec.annotations)
@unittest.skipIf(MISSING_C_DOCSTRINGS, @unittest.skipIf(MISSING_C_DOCSTRINGS,
...@@ -910,8 +904,7 @@ class TestClassesAndFunctions(unittest.TestCase): ...@@ -910,8 +904,7 @@ class TestClassesAndFunctions(unittest.TestCase):
def test_getfullargspec_builtin_func(self): def test_getfullargspec_builtin_func(self):
import _testcapi import _testcapi
builtin = _testcapi.docstring_with_signature_with_defaults builtin = _testcapi.docstring_with_signature_with_defaults
with self.assertWarns(DeprecationWarning): spec = inspect.getfullargspec(builtin)
spec = inspect.getfullargspec(builtin)
self.assertEqual(spec.defaults[0], 'avocado') self.assertEqual(spec.defaults[0], 'avocado')
@cpython_only @cpython_only
...@@ -920,20 +913,17 @@ class TestClassesAndFunctions(unittest.TestCase): ...@@ -920,20 +913,17 @@ class TestClassesAndFunctions(unittest.TestCase):
def test_getfullargspec_builtin_func_no_signature(self): def test_getfullargspec_builtin_func_no_signature(self):
import _testcapi import _testcapi
builtin = _testcapi.docstring_no_signature builtin = _testcapi.docstring_no_signature
with self.assertWarns(DeprecationWarning): with self.assertRaises(TypeError):
with self.assertRaises(TypeError): inspect.getfullargspec(builtin)
inspect.getfullargspec(builtin)
def test_getfullargspec_definition_order_preserved_on_kwonly(self): def test_getfullargspec_definition_order_preserved_on_kwonly(self):
for fn in signatures_with_lexicographic_keyword_only_parameters(): for fn in signatures_with_lexicographic_keyword_only_parameters():
with self.assertWarns(DeprecationWarning): signature = inspect.getfullargspec(fn)
signature = inspect.getfullargspec(fn)
l = list(signature.kwonlyargs) l = list(signature.kwonlyargs)
sorted_l = sorted(l) sorted_l = sorted(l)
self.assertTrue(l) self.assertTrue(l)
self.assertEqual(l, sorted_l) self.assertEqual(l, sorted_l)
with self.assertWarns(DeprecationWarning): signature = inspect.getfullargspec(unsorted_keyword_only_parameters_fn)
signature = inspect.getfullargspec(unsorted_keyword_only_parameters_fn)
l = list(signature.kwonlyargs) l = list(signature.kwonlyargs)
self.assertEqual(l, unsorted_keyword_only_parameters) self.assertEqual(l, unsorted_keyword_only_parameters)
...@@ -1390,9 +1380,8 @@ class TestGetcallargsFunctions(unittest.TestCase): ...@@ -1390,9 +1380,8 @@ class TestGetcallargsFunctions(unittest.TestCase):
def assertEqualCallArgs(self, func, call_params_string, locs=None): def assertEqualCallArgs(self, func, call_params_string, locs=None):
locs = dict(locs or {}, func=func) locs = dict(locs or {}, func=func)
r1 = eval('func(%s)' % call_params_string, None, locs) r1 = eval('func(%s)' % call_params_string, None, locs)
with self.assertWarns(DeprecationWarning): r2 = eval('inspect.getcallargs(func, %s)' % call_params_string, None,
r2 = eval('inspect.getcallargs(func, %s)' % call_params_string, None, locs)
locs)
self.assertEqual(r1, r2) self.assertEqual(r1, r2)
def assertEqualException(self, func, call_param_string, locs=None): def assertEqualException(self, func, call_param_string, locs=None):
...@@ -1404,9 +1393,8 @@ class TestGetcallargsFunctions(unittest.TestCase): ...@@ -1404,9 +1393,8 @@ class TestGetcallargsFunctions(unittest.TestCase):
else: else:
self.fail('Exception not raised') self.fail('Exception not raised')
try: try:
with self.assertWarns(DeprecationWarning): eval('inspect.getcallargs(func, %s)' % call_param_string, None,
eval('inspect.getcallargs(func, %s)' % call_param_string, None, locs)
locs)
except Exception as e: except Exception as e:
ex2 = e ex2 = e
else: else:
...@@ -1564,16 +1552,14 @@ class TestGetcallargsFunctions(unittest.TestCase): ...@@ -1564,16 +1552,14 @@ class TestGetcallargsFunctions(unittest.TestCase):
def f5(*, a): pass def f5(*, a): pass
with self.assertRaisesRegex(TypeError, with self.assertRaisesRegex(TypeError,
'missing 1 required keyword-only'): 'missing 1 required keyword-only'):
with self.assertWarns(DeprecationWarning): inspect.getcallargs(f5)
inspect.getcallargs(f5)
# issue20817: # issue20817:
def f6(a, b, c): def f6(a, b, c):
pass pass
with self.assertRaisesRegex(TypeError, "'a', 'b' and 'c'"): with self.assertRaisesRegex(TypeError, "'a', 'b' and 'c'"):
with self.assertWarns(DeprecationWarning): inspect.getcallargs(f6)
inspect.getcallargs(f6)
# bpo-33197 # bpo-33197
with self.assertRaisesRegex(ValueError, with self.assertRaisesRegex(ValueError,
......
...@@ -33,17 +33,6 @@ directory if the :envvar:`PATH` environment variable is not set. ...@@ -33,17 +33,6 @@ directory if the :envvar:`PATH` environment variable is not set.
.. ..
.. bpo: 36751
.. date: 2019-04-29-23-30-21
.. nonce: 3NCRbm
.. section: Core and Builtins
The :func:`~inspect.getfullargspec` function in the :mod:`inspect` module is
deprecated in favor of the :func:`inspect.signature` API. Contributed by
Pablo Galindo.
..
.. bpo: 36722 .. bpo: 36722
.. date: 2019-04-25-21-02-40 .. date: 2019-04-25-21-02-40
.. nonce: 8NApVM .. nonce: 8NApVM
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment