From 3cfec2e2fcab9f39121cec362b78ac235093ca1c Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Fri, 22 May 2015 11:38:38 -0400 Subject: [PATCH] Issue 20438: Deprecate inspect.getargspec() and friends. --- Doc/library/inspect.rst | 13 +++++++------ Lib/inspect.py | 5 ++++- Lib/test/test_inspect.py | 3 ++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 831882550a7..6543da974d5 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -815,15 +815,16 @@ Classes and functions The first four items in the tuple correspond to :func:`getargspec`. - .. note:: - Consider using the new :ref:`Signature Object ` - interface, which provides a better way of introspecting functions. - .. versionchanged:: 3.4 This function is now based on :func:`signature`, but still ignores ``__wrapped__`` attributes and includes the already bound first parameter in the signature output for bound methods. + .. deprecated:: 3.5 + Use :func:`signature` and + :ref:`Signature Object `, which provide a + better introspecting API for callables. + .. function:: getargvalues(frame) @@ -896,8 +897,8 @@ Classes and functions .. versionadded:: 3.2 - .. note:: - Consider using the new :meth:`Signature.bind` instead. + .. deprecated:: 3.5 + Use :meth:`Signature.bind` and :meth:`Signature.bind_partial` instead. .. function:: getclosurevars(func) diff --git a/Lib/inspect.py b/Lib/inspect.py index cbf38e7d181..48354f6d618 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1033,7 +1033,8 @@ def getargspec(func): and keyword arguments are supported. getargspec() will raise ValueError if the func has either annotations or keyword arguments. """ - + warnings.warn("inspect.getargspec() is deprecated, " + "use inspect.signature() instead", DeprecationWarning) args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \ getfullargspec(func) if kwonlyargs or ann: @@ -1057,6 +1058,8 @@ def getfullargspec(func): 'annotations' is a dictionary mapping argument names to annotations. The first four items in the tuple correspond to getargspec(). + + This function is deprecated, use inspect.signature() instead. """ try: diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 44405ee97ed..9492cadf096 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -631,7 +631,8 @@ class TestClassesAndFunctions(unittest.TestCase): def assertArgSpecEquals(self, routine, args_e, varargs_e=None, varkw_e=None, defaults_e=None, formatted=None): - args, varargs, varkw, defaults = inspect.getargspec(routine) + with self.assertWarns(DeprecationWarning): + args, varargs, varkw, defaults = inspect.getargspec(routine) self.assertEqual(args, args_e) self.assertEqual(varargs, varargs_e) self.assertEqual(varkw, varkw_e)