bpo-46529: increase coverage of `typing.Union.__repr__` method (GH-30911)

This commit is contained in:
Nikita Sobolev 2022-01-26 13:13:02 +03:00 committed by GitHub
parent b9d8980d89
commit d0c690b5f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -325,6 +325,15 @@ class UnionTests(BaseTestCase):
u = Union[int | float]
self.assertEqual(repr(u), 'typing.Union[int, float]')
u = Union[None, str]
self.assertEqual(repr(u), 'typing.Optional[str]')
u = Union[str, None]
self.assertEqual(repr(u), 'typing.Optional[str]')
u = Union[None, str, int]
self.assertEqual(repr(u), 'typing.Union[NoneType, str, int]')
u = Optional[str]
self.assertEqual(repr(u), 'typing.Optional[str]')
def test_cannot_subclass(self):
with self.assertRaises(TypeError):
class C(Union):