Skip to content

bpo-36751: Undeprecate getfullargspec #13245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,6 @@ Classes and functions
APIs. This function is retained primarily for use in code that needs to
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
This function is now based on :func:`signature`, but still ignores
``__wrapped__`` attributes and includes the already bound first
Expand Down
4 changes: 0 additions & 4 deletions Doc/whatsnew/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,6 @@ Deprecated
<positional-only_parameter>`.
(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
========================
Expand Down
6 changes: 0 additions & 6 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,16 +1103,10 @@ def getfullargspec(func):
'kwonlydefaults' is a dictionary mapping names from kwonlyargs to defaults.
'annotations' is a dictionary mapping parameter names to annotations.

.. deprecated:: 3.8
Use inspect.signature() instead of inspect.getfullargspec().

Notable differences from inspect.signature():
- the "self" parameter is always reported, even for bound methods
- wrapper chains defined by __wrapped__ *not* unwrapped automatically
"""

warnings.warn("Use inspect.signature() instead of inspect.getfullargspec()",
DeprecationWarning, stacklevel=2)
try:
# Re: `skip_bound_arg=False`
#
Expand Down
54 changes: 20 additions & 34 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,25 +750,22 @@ class D(B, C): pass

def assertArgSpecEquals(self, routine, args_e, varargs_e=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(varargs, varargs_e)
self.assertEqual(varkw, varkw_e)
self.assertEqual(defaults, defaults_e)
if formatted is not None:
with self.assertWarns(DeprecationWarning):
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults),
formatted)
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults),
formatted)

def assertFullArgSpecEquals(self, routine, args_e, varargs_e=None,
varkw_e=None, defaults_e=None,
posonlyargs_e=[], kwonlyargs_e=[],
kwonlydefaults_e=None,
ann_e={}, formatted=None):
with self.assertWarns(DeprecationWarning):
args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \
inspect.getfullargspec(routine)
args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \
inspect.getfullargspec(routine)
self.assertEqual(args, args_e)
self.assertEqual(varargs, varargs_e)
self.assertEqual(varkw, varkw_e)
Expand All @@ -777,9 +774,8 @@ def assertFullArgSpecEquals(self, routine, args_e, varargs_e=None,
self.assertEqual(kwonlydefaults, kwonlydefaults_e)
self.assertEqual(ann, ann_e)
if formatted is not None:
with self.assertWarns(DeprecationWarning):
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults,
kwonlyargs, kwonlydefaults, ann),
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults,
kwonlyargs, kwonlydefaults, ann),
formatted)

def test_getargspec(self):
Expand Down Expand Up @@ -879,13 +875,11 @@ def test():

def test_getfullargspec_signature_annos(self):
def test(a:'spam') -> 'ham': pass
with self.assertWarns(DeprecationWarning):
spec = inspect.getfullargspec(test)
spec = inspect.getfullargspec(test)
self.assertEqual(test.__annotations__, spec.annotations)

def test(): pass
with self.assertWarns(DeprecationWarning):
spec = inspect.getfullargspec(test)
spec = inspect.getfullargspec(test)
self.assertEqual(test.__annotations__, spec.annotations)

@unittest.skipIf(MISSING_C_DOCSTRINGS,
Expand All @@ -910,8 +904,7 @@ def test_getfullargspec_builtin_methods(self):
def test_getfullargspec_builtin_func(self):
import _testcapi
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')

@cpython_only
Expand All @@ -920,20 +913,17 @@ def test_getfullargspec_builtin_func(self):
def test_getfullargspec_builtin_func_no_signature(self):
import _testcapi
builtin = _testcapi.docstring_no_signature
with self.assertWarns(DeprecationWarning):
with self.assertRaises(TypeError):
inspect.getfullargspec(builtin)
with self.assertRaises(TypeError):
inspect.getfullargspec(builtin)

def test_getfullargspec_definition_order_preserved_on_kwonly(self):
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)
sorted_l = sorted(l)
self.assertTrue(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)
self.assertEqual(l, unsorted_keyword_only_parameters)

Expand Down Expand Up @@ -1390,9 +1380,8 @@ class TestGetcallargsFunctions(unittest.TestCase):
def assertEqualCallArgs(self, func, call_params_string, locs=None):
locs = dict(locs or {}, func=func)
r1 = eval('func(%s)' % call_params_string, None, locs)
with self.assertWarns(DeprecationWarning):
r2 = eval('inspect.getcallargs(func, %s)' % call_params_string, None,
locs)
r2 = eval('inspect.getcallargs(func, %s)' % call_params_string, None,
locs)
self.assertEqual(r1, r2)

def assertEqualException(self, func, call_param_string, locs=None):
Expand All @@ -1404,9 +1393,8 @@ def assertEqualException(self, func, call_param_string, locs=None):
else:
self.fail('Exception not raised')
try:
with self.assertWarns(DeprecationWarning):
eval('inspect.getcallargs(func, %s)' % call_param_string, None,
locs)
eval('inspect.getcallargs(func, %s)' % call_param_string, None,
locs)
except Exception as e:
ex2 = e
else:
Expand Down Expand Up @@ -1564,16 +1552,14 @@ def test_errors(self):
def f5(*, a): pass
with self.assertRaisesRegex(TypeError,
'missing 1 required keyword-only'):
with self.assertWarns(DeprecationWarning):
inspect.getcallargs(f5)
inspect.getcallargs(f5)


# issue20817:
def f6(a, b, c):
pass
with self.assertRaisesRegex(TypeError, "'a', 'b' and 'c'"):
with self.assertWarns(DeprecationWarning):
inspect.getcallargs(f6)
inspect.getcallargs(f6)

# bpo-33197
with self.assertRaisesRegex(ValueError,
Expand Down
11 changes: 0 additions & 11 deletions Misc/NEWS.d/3.8.0a4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
.. date: 2019-04-25-21-02-40
.. nonce: 8NApVM
Expand Down