Skip to content

bpo-46359: continue to modernize test_typing #30563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1940,13 +1940,12 @@ class A(Generic[T]):
self.assertNotEqual(typing.FrozenSet[A[str]],
typing.FrozenSet[mod_generics_cache.B.A[str]])

if sys.version_info[:2] > (3, 2):
self.assertTrue(repr(Tuple[A[str]]).endswith('<locals>.A[str]]'))
self.assertTrue(repr(Tuple[B.A[str]]).endswith('<locals>.B.A[str]]'))
self.assertTrue(repr(Tuple[mod_generics_cache.A[str]])
.endswith('mod_generics_cache.A[str]]'))
self.assertTrue(repr(Tuple[mod_generics_cache.B.A[str]])
.endswith('mod_generics_cache.B.A[str]]'))
self.assertTrue(repr(Tuple[A[str]]).endswith('<locals>.A[str]]'))
self.assertTrue(repr(Tuple[B.A[str]]).endswith('<locals>.B.A[str]]'))
self.assertTrue(repr(Tuple[mod_generics_cache.A[str]])
.endswith('mod_generics_cache.A[str]]'))
self.assertTrue(repr(Tuple[mod_generics_cache.B.A[str]])
.endswith('mod_generics_cache.B.A[str]]'))

def test_extended_generic_rules_eq(self):
T = TypeVar('T')
Expand Down Expand Up @@ -2065,11 +2064,9 @@ class MyDict(typing.Dict[T, T]): ...
class MyDef(typing.DefaultDict[str, T]): ...
self.assertIs(MyDef[int]().__class__, MyDef)
self.assertEqual(MyDef[int]().__orig_class__, MyDef[int])
# ChainMap was added in 3.3
if sys.version_info >= (3, 3):
class MyChain(typing.ChainMap[str, T]): ...
self.assertIs(MyChain[int]().__class__, MyChain)
self.assertEqual(MyChain[int]().__orig_class__, MyChain[int])
class MyChain(typing.ChainMap[str, T]): ...
self.assertIs(MyChain[int]().__class__, MyChain)
self.assertEqual(MyChain[int]().__orig_class__, MyChain[int])

def test_all_repr_eq_any(self):
objs = (getattr(typing, el) for el in typing.__all__)
Expand Down Expand Up @@ -4090,14 +4087,6 @@ def test_basics(self):
self.assertEqual(Emp.__annotations__,
collections.OrderedDict([('name', str), ('id', int)]))

def test_namedtuple_pyversion(self):
if sys.version_info[:2] < (3, 6):
with self.assertRaises(TypeError):
NamedTuple('Name', one=int, other=str)
with self.assertRaises(TypeError):
class NotYet(NamedTuple):
whatever = 0

def test_annotation_usage(self):
tim = CoolEmployee('Tim', 9000)
self.assertIsInstance(tim, CoolEmployee)
Expand Down