mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
Issue #25486: Resurrect inspect.getargspec in 3.6. Backout a565aad5d6e1.
The decision is that we shouldn't remove popular APIs (however long they are depreacted) from Python 3, while 2.7 is still around and supported.
This commit is contained in:
parent
ec71f1779f
commit
37dc2b2883
5 changed files with 79 additions and 10 deletions
|
|
@ -628,6 +628,18 @@ 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,
|
||||
|
|
@ -646,6 +658,23 @@ 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'],
|
||||
|
|
@ -659,19 +688,20 @@ class TestClassesAndFunctions(unittest.TestCase):
|
|||
kwonlyargs_e=['arg'],
|
||||
formatted='(*, arg)')
|
||||
|
||||
def test_fullargspec_api_ignores_wrapped(self):
|
||||
def test_argspec_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.assertFullArgSpecEquals(f, ['self', 'x', 'y'],
|
||||
formatted='(self, x, y)')
|
||||
self.assertArgSpecEquals(f, ['self', 'x', 'y'],
|
||||
formatted='(self, x, y)')
|
||||
class C:
|
||||
@functools.wraps(mod.spam)
|
||||
def ham(self, x, y):
|
||||
|
|
@ -749,11 +779,11 @@ class TestClassesAndFunctions(unittest.TestCase):
|
|||
with self.assertRaises(TypeError):
|
||||
inspect.getfullargspec(builtin)
|
||||
|
||||
def test_getfullargspec_method(self):
|
||||
def test_getargspec_method(self):
|
||||
class A(object):
|
||||
def m(self):
|
||||
pass
|
||||
self.assertFullArgSpecEquals(A.m, ['self'])
|
||||
self.assertArgSpecEquals(A.m, ['self'])
|
||||
|
||||
def test_classify_newstyle(self):
|
||||
class A(object):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue