(original) (raw)
changeset: 97023:a565aad5d6e1 user: Yury Selivanov yselivanov@sprymix.com date: Thu Jul 23 17:36:02 2015 +0300 files: Doc/library/inspect.rst Doc/whatsnew/3.6.rst Lib/inspect.py Lib/test/test_inspect.py description: Issue #13248: Remove inspect.getargspec from 3.6 (deprecated from 3.0) diff -r 98a2bbf2cce2 -r a565aad5d6e1 Doc/library/inspect.rst --- a/Doc/library/inspect.rst Thu Jul 23 17:10:24 2015 +0300 +++ b/Doc/library/inspect.rst Thu Jul 23 17:36:02 2015 +0300 @@ -805,24 +805,6 @@ 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 or ``None``. *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 - :ref:`Signature Object `, which provide a - better introspecting API for callables. This function will be removed - in Python 3.6. - - .. function:: getfullargspec(func) Get the names and default values of a Python function's arguments. A diff -r 98a2bbf2cce2 -r a565aad5d6e1 Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst Thu Jul 23 17:10:24 2015 +0300 +++ b/Doc/whatsnew/3.6.rst Thu Jul 23 17:36:02 2015 +0300 @@ -145,7 +145,8 @@ API and Feature Removals ------------------------ -* None yet. +* ``inspect.getargspec()`` was removed (was deprecated since CPython 3.0). + :func:`inspect.getfullargspec` is an almost drop in replacement. Porting to Python 3.6 diff -r 98a2bbf2cce2 -r a565aad5d6e1 Lib/inspect.py --- a/Lib/inspect.py Thu Jul 23 17:10:24 2015 +0300 +++ b/Lib/inspect.py Thu Jul 23 17:36:02 2015 +0300 @@ -1002,31 +1002,6 @@ varkw = co.co_varnames[nargs] return args, varargs, kwonlyargs, varkw - -ArgSpec = namedtuple('ArgSpec', 'args varargs keywords defaults') - -def getargspec(func): - """Get the names and default values of a function's arguments. - - 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, - stacklevel=2) - args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \ - getfullargspec(func) - if kwonlyargs or ann: - raise ValueError("Function has keyword-only arguments or annotations" - ", use getfullargspec() API which can support them") - return ArgSpec(args, varargs, varkw, defaults) - FullArgSpec = namedtuple('FullArgSpec', 'args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations') diff -r 98a2bbf2cce2 -r a565aad5d6e1 Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py Thu Jul 23 17:10:24 2015 +0300 +++ b/Lib/test/test_inspect.py Thu Jul 23 17:36:02 2015 +0300 @@ -629,18 +629,6 @@ 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): - 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) - self.assertEqual(defaults, defaults_e) - if formatted is not None: - self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults), - formatted) - def assertFullArgSpecEquals(self, routine, args_e, varargs_e=None, varkw_e=None, defaults_e=None, kwonlyargs_e=[], kwonlydefaults_e=None, @@ -659,23 +647,6 @@ kwonlyargs, kwonlydefaults, ann), formatted) - def test_getargspec(self): - self.assertArgSpecEquals(mod.eggs, ['x', 'y'], formatted='(x, y)') - - self.assertArgSpecEquals(mod.spam, - ['a', 'b', 'c', 'd', 'e', 'f'], - 'g', 'h', (3, 4, 5), - '(a, b, c, d=3, e=4, f=5, *g, **h)') - - self.assertRaises(ValueError, self.assertArgSpecEquals, - mod2.keyworded, []) - - self.assertRaises(ValueError, self.assertArgSpecEquals, - mod2.annotated, []) - self.assertRaises(ValueError, self.assertArgSpecEquals, - mod2.keyword_only_arg, []) - - def test_getfullargspec(self): self.assertFullArgSpecEquals(mod2.keyworded, [], varargs_e='arg1', kwonlyargs_e=['arg2'], @@ -689,20 +660,19 @@ kwonlyargs_e=['arg'], formatted='(*, arg)') - def test_argspec_api_ignores_wrapped(self): + 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)') self.assertFullArgSpecEquals(ham, ['x', 'y'], formatted='(x, y)') self.assertFullArgSpecEquals(functools.partial(ham), ['x', 'y'], formatted='(x, y)') # Other variants def check_method(f): - self.assertArgSpecEquals(f, ['self', 'x', 'y'], - formatted='(self, x, y)') + self.assertFullArgSpecEquals(f, ['self', 'x', 'y'], + formatted='(self, x, y)') class C: @functools.wraps(mod.spam) def ham(self, x, y): @@ -780,11 +750,11 @@ with self.assertRaises(TypeError): inspect.getfullargspec(builtin) - def test_getargspec_method(self): + def test_getfullargspec_method(self): class A(object): def m(self): pass - self.assertArgSpecEquals(A.m, ['self']) + self.assertFullArgSpecEquals(A.m, ['self']) def test_classify_newstyle(self): class A(object):/yselivanov@sprymix.com