Skip to content

Commit 2a8f9ed

Browse files
committed
AsyncGenerator: remove redundant __new__, add test case for instantiation
1 parent 04b3013 commit 2a8f9ed

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/test_typing.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,12 @@ def g(): yield 0
17851785

17861786
@skipUnless(PY36, 'Python 3.6 required')
17871787
def test_subclassing_async_generator(self):
1788-
class G(typing.AsyncGenerator[int, int]): ...
1788+
class G(typing.AsyncGenerator[int, int]):
1789+
def asend(self, value):
1790+
pass
1791+
def athrow(self, typ, val=None, tb=None):
1792+
pass
1793+
17891794
ns = {}
17901795
exec('async def g(): yield 0', globals(), ns)
17911796
g = ns['g']
@@ -1795,6 +1800,13 @@ class G(typing.AsyncGenerator[int, int]): ...
17951800
self.assertIsSubclass(G, collections.AsyncIterable)
17961801
self.assertNotIsSubclass(type(g), G)
17971802

1803+
instance = G()
1804+
self.assertIsInstance(instance, typing.AsyncGenerator)
1805+
self.assertIsInstance(instance, typing.AsyncIterable)
1806+
self.assertIsInstance(instance, collections.AsyncGenerator)
1807+
self.assertIsInstance(instance, collections.AsyncIterable)
1808+
self.assertNotIsInstance(type(g), G)
1809+
17981810
def test_subclassing_subclasshook(self):
17991811

18001812
class Base(typing.Iterable):

src/typing.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,12 +1867,6 @@ class AsyncGenerator(AsyncIterator[T_co], Generic[T_co, T_contra],
18671867
extra=_AG_base):
18681868
__slots__ = ()
18691869

1870-
def __new__(cls, *args, **kwds):
1871-
if _geqv(cls, AsyncGenerator):
1872-
raise TypeError("Type AsyncGenerator cannot be instantiated; "
1873-
"create a subclass instead")
1874-
return _generic_new(_AG_base, cls, *args, **kwds)
1875-
18761870
__all__.append('AsyncGenerator')
18771871

18781872

0 commit comments

Comments
 (0)