cpython: a565aad5d6e1 (original) (raw)
--- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -805,24 +805,6 @@ Classes and functions classes using multiple inheritance and their descendants will appear multiple times. - -.. function:: getargspec(func) -
- Get the names and default values of a Python function's arguments. A
- :term:
named tuple
ArgSpec(args, varargs, keywords, defaults)
is - returned. args is a list of the argument names. varargs and keywords
- are the names of the
*
and**
arguments orNone
. defaults is a - tuple of default argument values or
None
if there are no default - arguments; if this tuple has n elements, they correspond to the last
- n elements listed in args. -
- .. deprecated:: 3.0
Use :func:`signature` and[](#l1.19)
:ref:`Signature Object <inspect-signature-object>`, which provide a[](#l1.20)
better introspecting API for callables. This function will be removed[](#l1.21)
in Python 3.6.[](#l1.22)
- - .. function:: getfullargspec(func) Get the names and default values of a Python function's arguments. A
--- a/Doc/whatsnew/3.6.rst
+++ b/Doc/whatsnew/3.6.rst
@@ -145,7 +145,8 @@ Removed
API and Feature Removals
------------------------
-* None yet.
+* inspect.getargspec()
was removed (was deprecated since CPython 3.0).
--- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1002,31 +1002,6 @@ def _getfullargs(co): varkw = co.co_varnames[nargs] return args, varargs, kwonlyargs, varkw - -ArgSpec = namedtuple('ArgSpec', 'args varargs keywords defaults') - -def getargspec(func):
- A tuple of four things is returned: (args, varargs, keywords, defaults).
- 'args' is a list of the argument names, including keyword-only argument names.
- 'varargs' and 'keywords' are the names of the * and ** arguments or None.
- 'defaults' is an n-tuple of the default values of the last n arguments.
- Use the getfullargspec() API for Python 3 code, as annotations
- 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,[](#l3.23)
stacklevel=2)[](#l3.24)
- args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = [](#l3.25)
getfullargspec(func)[](#l3.26)
- if kwonlyargs or ann:
raise ValueError("Function has keyword-only arguments or annotations"[](#l3.28)
", use getfullargspec() API which can support them")[](#l3.29)
- return ArgSpec(args, varargs, varkw, defaults)
- FullArgSpec = namedtuple('FullArgSpec', 'args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations')
--- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -629,18 +629,6 @@ class TestClassesAndFunctions(unittest.T got = inspect.getmro(D) self.assertEqual(expected, got)
- def assertArgSpecEquals(self, routine, args_e, varargs_e=None,
varkw_e=None, defaults_e=None, formatted=None):[](#l4.8)
with self.assertWarns(DeprecationWarning):[](#l4.9)
args, varargs, varkw, defaults = inspect.getargspec(routine)[](#l4.10)
self.assertEqual(args, args_e)[](#l4.11)
self.assertEqual(varargs, varargs_e)[](#l4.12)
self.assertEqual(varkw, varkw_e)[](#l4.13)
self.assertEqual(defaults, defaults_e)[](#l4.14)
if formatted is not None:[](#l4.15)
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults),[](#l4.16)
formatted)[](#l4.17)
- def assertFullArgSpecEquals(self, routine, args_e, varargs_e=None, varkw_e=None, defaults_e=None, kwonlyargs_e=[], kwonlydefaults_e=None, @@ -659,23 +647,6 @@ class TestClassesAndFunctions(unittest.T kwonlyargs, kwonlydefaults, ann), formatted)
- def test_getargspec(self):
self.assertArgSpecEquals(mod.eggs, ['x', 'y'], formatted='(x, y)')[](#l4.27)
self.assertArgSpecEquals(mod.spam,[](#l4.29)
['a', 'b', 'c', 'd', 'e', 'f'],[](#l4.30)
'g', 'h', (3, 4, 5),[](#l4.31)
'(a, b, c, d=3, e=4, f=5, *g, **h)')[](#l4.32)
self.assertRaises(ValueError, self.assertArgSpecEquals,[](#l4.34)
mod2.keyworded, [])[](#l4.35)
self.assertRaises(ValueError, self.assertArgSpecEquals,[](#l4.37)
mod2.annotated, [])[](#l4.38)
self.assertRaises(ValueError, self.assertArgSpecEquals,[](#l4.39)
mod2.keyword_only_arg, [])[](#l4.40)
- - def test_getfullargspec(self): self.assertFullArgSpecEquals(mod2.keyworded, [], varargs_e='arg1', kwonlyargs_e=['arg2'], @@ -689,20 +660,19 @@ class TestClassesAndFunctions(unittest.T kwonlyargs_e=['arg'], formatted='(*, arg)')
- def test_fullargspec_api_ignores_wrapped(self): # Issue 20684: low level introspection API must ignore wrapped @functools.wraps(mod.spam) def ham(x, y): pass # Basic check
self.assertArgSpecEquals(ham, ['x', 'y'], formatted='(x, y)')[](#l4.57) self.assertFullArgSpecEquals(ham, ['x', 'y'], formatted='(x, y)')[](#l4.58) self.assertFullArgSpecEquals(functools.partial(ham),[](#l4.59) ['x', 'y'], formatted='(x, y)')[](#l4.60) # Other variants[](#l4.61) def check_method(f):[](#l4.62)
self.assertArgSpecEquals(f, ['self', 'x', 'y'],[](#l4.63)
formatted='(self, x, y)')[](#l4.64)
self.assertFullArgSpecEquals(f, ['self', 'x', 'y'],[](#l4.65)
formatted='(self, x, y)')[](#l4.66) class C:[](#l4.67) @functools.wraps(mod.spam)[](#l4.68) def ham(self, x, y):[](#l4.69)
@@ -780,11 +750,11 @@ class TestClassesAndFunctions(unittest.T with self.assertRaises(TypeError): inspect.getfullargspec(builtin)
self.assertArgSpecEquals(A.m, ['self'])[](#l4.79)
self.assertFullArgSpecEquals(A.m, ['self'])[](#l4.80)