gh-118647: Add defaults to typing.Generator and typing.AsyncGenerator (#118648)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Jelle Zijlstra 2024-05-06 15:35:06 -07:00 committed by GitHub
parent 9fd33af5ac
commit 8419f01673
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 51 additions and 9 deletions

View file

@ -7289,6 +7289,17 @@ class CollectionsAbcTests(BaseTestCase):
g = foo()
self.assertIsSubclass(type(g), typing.Generator)
def test_generator_default(self):
g1 = typing.Generator[int]
g2 = typing.Generator[int, None, None]
self.assertEqual(get_args(g1), (int, type(None), type(None)))
self.assertEqual(get_args(g1), get_args(g2))
g3 = typing.Generator[int, float]
g4 = typing.Generator[int, float, None]
self.assertEqual(get_args(g3), (int, float, type(None)))
self.assertEqual(get_args(g3), get_args(g4))
def test_no_generator_instantiation(self):
with self.assertRaises(TypeError):
typing.Generator()