]> granicus.if.org Git - python/commitdiff
Issue #13248: Remove inspect.getargspec from 3.6 (deprecated from 3.0)
authorYury Selivanov <yselivanov@sprymix.com>
Thu, 23 Jul 2015 14:36:02 +0000 (17:36 +0300)
committerYury Selivanov <yselivanov@sprymix.com>
Thu, 23 Jul 2015 14:36:02 +0000 (17:36 +0300)
Doc/library/inspect.rst
Doc/whatsnew/3.6.rst
Lib/inspect.py
Lib/test/test_inspect.py

index 66b92384f0722e7dedb520ad99a1a8d75cb95597..b5c4a7aac0960a0fe973a9319781d99ef047a5fa 100644 (file)
@@ -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 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 <inspect-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
index 375d94e55189701643f26b3f2a92d62fcd8c8103..b6388d59734ac6a18e33ffd3d3d85dfa15b01bfc 100644 (file)
@@ -145,7 +145,8 @@ Removed
 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
index 24c8df722513a51b40eb8454d5cc4b522562ac57..4e78d80cf549ef2e6c260260cfe87cf5164fd465 100644 (file)
@@ -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):
-    """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')
 
index 042617b60dc1c80e61a1cd317617ddd2870c77fe..bd0605e6c37d36e66c884ca7bd534a84f37ebde1 100644 (file)
@@ -629,18 +629,6 @@ class TestClassesAndFunctions(unittest.TestCase):
         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 @@ class TestClassesAndFunctions(unittest.TestCase):
                                                     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 @@ class TestClassesAndFunctions(unittest.TestCase):
                                      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 @@ class TestClassesAndFunctions(unittest.TestCase):
         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):