bpo-38605: Revert making 'from __future__ import annotations' the default (GH-25490)

This reverts commits 044a1048ca and 1be456ae9d, adapting the code to changes that happened after it.
This commit is contained in:
Pablo Galindo 2021-04-21 12:41:19 +01:00 committed by GitHub
parent d35eef3b90
commit b0544ba77c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 436 additions and 523 deletions

View file

@ -363,7 +363,7 @@ class UnionTests(BaseTestCase):
def test_no_eval_union(self):
u = Union[int, str]
def f(x: u): ...
self.assertIs(get_type_hints(f, globals(), locals())['x'], u)
self.assertIs(get_type_hints(f)['x'], u)
def test_function_repr_union(self):
def fun() -> int: ...
@ -2876,7 +2876,7 @@ class GetTypeHintTests(BaseTestCase):
self.assertEqual(gth(HasForeignBaseClass),
{'some_xrepr': XRepr, 'other_a': mod_generics_cache.A,
'some_b': mod_generics_cache.B})
self.assertEqual(gth(XRepr),
self.assertEqual(gth(XRepr.__new__),
{'x': int, 'y': int})
self.assertEqual(gth(mod_generics_cache.B),
{'my_inner_a1': mod_generics_cache.B.A,
@ -3689,7 +3689,7 @@ class NamedTupleTests(BaseTestCase):
self.assertEqual(tim.cool, 9000)
self.assertEqual(CoolEmployee.__name__, 'CoolEmployee')
self.assertEqual(CoolEmployee._fields, ('name', 'cool'))
self.assertEqual(gth(CoolEmployee),
self.assertEqual(CoolEmployee.__annotations__,
collections.OrderedDict(name=str, cool=int))
def test_annotation_usage_with_default(self):
@ -3703,7 +3703,7 @@ class NamedTupleTests(BaseTestCase):
self.assertEqual(CoolEmployeeWithDefault.__name__, 'CoolEmployeeWithDefault')
self.assertEqual(CoolEmployeeWithDefault._fields, ('name', 'cool'))
self.assertEqual(gth(CoolEmployeeWithDefault),
self.assertEqual(CoolEmployeeWithDefault.__annotations__,
dict(name=str, cool=int))
self.assertEqual(CoolEmployeeWithDefault._field_defaults, dict(cool=0))
@ -3871,7 +3871,7 @@ class TypedDictTests(BaseTestCase):
def test_py36_class_syntax_usage(self):
self.assertEqual(LabelPoint2D.__name__, 'LabelPoint2D')
self.assertEqual(LabelPoint2D.__module__, __name__)
self.assertEqual(gth(LabelPoint2D), {'x': int, 'y': int, 'label': str})
self.assertEqual(LabelPoint2D.__annotations__, {'x': int, 'y': int, 'label': str})
self.assertEqual(LabelPoint2D.__bases__, (dict,))
self.assertEqual(LabelPoint2D.__total__, True)
self.assertNotIsSubclass(LabelPoint2D, typing.Sequence)
@ -3934,11 +3934,11 @@ class TypedDictTests(BaseTestCase):
assert BaseAnimal.__required_keys__ == frozenset(['name'])
assert BaseAnimal.__optional_keys__ == frozenset([])
assert gth(BaseAnimal) == {'name': str}
assert BaseAnimal.__annotations__ == {'name': str}
assert Animal.__required_keys__ == frozenset(['name'])
assert Animal.__optional_keys__ == frozenset(['tail', 'voice'])
assert gth(Animal) == {
assert Animal.__annotations__ == {
'name': str,
'tail': bool,
'voice': str,
@ -3946,7 +3946,7 @@ class TypedDictTests(BaseTestCase):
assert Cat.__required_keys__ == frozenset(['name', 'fur_color'])
assert Cat.__optional_keys__ == frozenset(['tail', 'voice'])
assert gth(Cat) == {
assert Cat.__annotations__ == {
'fur_color': str,
'name': str,
'tail': bool,
@ -3967,7 +3967,7 @@ class IOTests(BaseTestCase):
def stuff(a: IO) -> AnyStr:
return a.readline()
a = gth(stuff)['a']
a = stuff.__annotations__['a']
self.assertEqual(a.__parameters__, (AnyStr,))
def test_textio(self):
@ -3975,7 +3975,7 @@ class IOTests(BaseTestCase):
def stuff(a: TextIO) -> str:
return a.readline()
a = gth(stuff)['a']
a = stuff.__annotations__['a']
self.assertEqual(a.__parameters__, ())
def test_binaryio(self):
@ -3983,7 +3983,7 @@ class IOTests(BaseTestCase):
def stuff(a: BinaryIO) -> bytes:
return a.readline()
a = gth(stuff)['a']
a = stuff.__annotations__['a']
self.assertEqual(a.__parameters__, ())
def test_io_submodule(self):