mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
bpo-38605: Revert making 'from __future__ import annotations' the default (GH-25490)
This reverts commits044a1048ca
and1be456ae9d
, adapting the code to changes that happened after it.
This commit is contained in:
parent
d35eef3b90
commit
b0544ba77c
32 changed files with 436 additions and 523 deletions
|
@ -888,7 +888,7 @@ class TestClassesAndFunctions(unittest.TestCase):
|
|||
|
||||
self.assertFullArgSpecEquals(mod2.annotated, ['arg1'],
|
||||
ann_e={'arg1' : list},
|
||||
formatted="(arg1: list)")
|
||||
formatted='(arg1: list)')
|
||||
self.assertFullArgSpecEquals(mod2.keyword_only_arg, [],
|
||||
kwonlyargs_e=['arg'],
|
||||
formatted='(*, arg)')
|
||||
|
@ -2237,8 +2237,8 @@ class TestSignatureObject(unittest.TestCase):
|
|||
pass
|
||||
self.assertEqual(self.signature(test),
|
||||
((('a', ..., ..., "positional_or_keyword"),
|
||||
('b', ..., repr('foo'), "positional_or_keyword")),
|
||||
'123'))
|
||||
('b', ..., 'foo', "positional_or_keyword")),
|
||||
123))
|
||||
|
||||
def test_signature_on_wkwonly(self):
|
||||
def test(*, a:float, b:str) -> int:
|
||||
|
@ -2253,11 +2253,11 @@ class TestSignatureObject(unittest.TestCase):
|
|||
pass
|
||||
self.assertEqual(self.signature(test),
|
||||
((('a', ..., ..., "positional_or_keyword"),
|
||||
('b', 10, repr('foo'), "positional_or_keyword"),
|
||||
('args', ..., repr('bar'), "var_positional"),
|
||||
('spam', ..., repr('baz'), "keyword_only"),
|
||||
('b', 10, 'foo', "positional_or_keyword"),
|
||||
('args', ..., 'bar', "var_positional"),
|
||||
('spam', ..., 'baz', "keyword_only"),
|
||||
('ham', 123, ..., "keyword_only"),
|
||||
('kwargs', ..., 'int', "var_keyword")),
|
||||
('kwargs', ..., int, "var_keyword")),
|
||||
...))
|
||||
|
||||
def test_signature_without_self(self):
|
||||
|
@ -2666,12 +2666,12 @@ class TestSignatureObject(unittest.TestCase):
|
|||
|
||||
self.assertEqual(self.signature(partial(partial(test, 1))),
|
||||
((('b', ..., ..., "positional_or_keyword"),
|
||||
('c', ..., 'int', "positional_or_keyword")),
|
||||
'42'))
|
||||
('c', ..., int, "positional_or_keyword")),
|
||||
42))
|
||||
|
||||
self.assertEqual(self.signature(partial(partial(test, 1), 2)),
|
||||
((('c', ..., 'int', "positional_or_keyword"),),
|
||||
'42'))
|
||||
((('c', ..., int, "positional_or_keyword"),),
|
||||
42))
|
||||
|
||||
psig = inspect.signature(partial(partial(test, 1), 2))
|
||||
|
||||
|
@ -2790,12 +2790,12 @@ class TestSignatureObject(unittest.TestCase):
|
|||
((('it', ..., ..., 'positional_or_keyword'),
|
||||
('a', ..., ..., 'positional_or_keyword'),
|
||||
('c', 1, ..., 'keyword_only')),
|
||||
repr('spam')))
|
||||
'spam'))
|
||||
|
||||
self.assertEqual(self.signature(Spam().ham),
|
||||
((('a', ..., ..., 'positional_or_keyword'),
|
||||
('c', 1, ..., 'keyword_only')),
|
||||
repr('spam')))
|
||||
'spam'))
|
||||
|
||||
class Spam:
|
||||
def test(self: 'anno', x):
|
||||
|
@ -2804,7 +2804,7 @@ class TestSignatureObject(unittest.TestCase):
|
|||
g = partialmethod(test, 1)
|
||||
|
||||
self.assertEqual(self.signature(Spam.g),
|
||||
((('self', ..., repr('anno'), 'positional_or_keyword'),),
|
||||
((('self', ..., 'anno', 'positional_or_keyword'),),
|
||||
...))
|
||||
|
||||
def test_signature_on_fake_partialmethod(self):
|
||||
|
@ -3142,16 +3142,20 @@ class TestSignatureObject(unittest.TestCase):
|
|||
with self.assertRaisesRegex(TypeError, 'unhashable type'):
|
||||
hash(inspect.signature(foo))
|
||||
|
||||
def foo(a) -> {}: pass
|
||||
with self.assertRaisesRegex(TypeError, 'unhashable type'):
|
||||
hash(inspect.signature(foo))
|
||||
|
||||
def test_signature_str(self):
|
||||
def foo(a:int=1, *, b, c=None, **kwargs) -> 42:
|
||||
pass
|
||||
self.assertEqual(str(inspect.signature(foo)),
|
||||
'(a: \'int\' = 1, *, b, c=None, **kwargs) -> \'42\'')
|
||||
'(a: int = 1, *, b, c=None, **kwargs) -> 42')
|
||||
|
||||
def foo(a:int=1, *args, b, c=None, **kwargs) -> 42:
|
||||
pass
|
||||
self.assertEqual(str(inspect.signature(foo)),
|
||||
'(a: \'int\' = 1, *args, b, c=None, **kwargs) -> \'42\'')
|
||||
'(a: int = 1, *args, b, c=None, **kwargs) -> 42')
|
||||
|
||||
def foo():
|
||||
pass
|
||||
|
@ -3194,8 +3198,8 @@ class TestSignatureObject(unittest.TestCase):
|
|||
self.assertIs(sig.return_annotation, None)
|
||||
sig = sig.replace(return_annotation=sig.empty)
|
||||
self.assertIs(sig.return_annotation, sig.empty)
|
||||
sig = sig.replace(return_annotation='42')
|
||||
self.assertEqual(sig.return_annotation, '42')
|
||||
sig = sig.replace(return_annotation=42)
|
||||
self.assertEqual(sig.return_annotation, 42)
|
||||
self.assertEqual(sig, inspect.signature(test))
|
||||
|
||||
def test_signature_on_mangled_parameters(self):
|
||||
|
@ -3207,8 +3211,8 @@ class TestSignatureObject(unittest.TestCase):
|
|||
|
||||
self.assertEqual(self.signature(Spam.foo),
|
||||
((('self', ..., ..., "positional_or_keyword"),
|
||||
('_Spam__p1', 2, '1', "positional_or_keyword"),
|
||||
('_Spam__p2', 3, '2', "keyword_only")),
|
||||
('_Spam__p1', 2, 1, "positional_or_keyword"),
|
||||
('_Spam__p2', 3, 2, "keyword_only")),
|
||||
...))
|
||||
|
||||
self.assertEqual(self.signature(Spam.foo),
|
||||
|
@ -3253,13 +3257,13 @@ class TestSignatureObject(unittest.TestCase):
|
|||
def test_signature_annotations_with_local_namespaces(self):
|
||||
class Foo: ...
|
||||
def func(foo: Foo) -> int: pass
|
||||
def func2(foo: Foo, bar: Bar) -> int: pass
|
||||
def func2(foo: Foo, bar: 'Bar') -> int: pass
|
||||
|
||||
for signature_func in (inspect.signature, inspect.Signature.from_callable):
|
||||
with self.subTest(signature_func = signature_func):
|
||||
sig1 = signature_func(func)
|
||||
self.assertEqual(sig1.return_annotation, 'int')
|
||||
self.assertEqual(sig1.parameters['foo'].annotation, 'Foo')
|
||||
self.assertEqual(sig1.return_annotation, int)
|
||||
self.assertEqual(sig1.parameters['foo'].annotation, Foo)
|
||||
|
||||
sig2 = signature_func(func, localns=locals())
|
||||
self.assertEqual(sig2.return_annotation, int)
|
||||
|
@ -3268,7 +3272,7 @@ class TestSignatureObject(unittest.TestCase):
|
|||
sig3 = signature_func(func2, globalns={'Bar': int}, localns=locals())
|
||||
self.assertEqual(sig3.return_annotation, int)
|
||||
self.assertEqual(sig3.parameters['foo'].annotation, Foo)
|
||||
self.assertEqual(sig3.parameters['bar'].annotation, int)
|
||||
self.assertEqual(sig3.parameters['bar'].annotation, 'Bar')
|
||||
|
||||
|
||||
class TestParameterObject(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue