@@ -1320,6 +1320,7 @@ def blah():
1320
1320
1321
1321
1322
1322
ASYNCIO = sys .version_info [:2 ] >= (3 , 5 )
1323
+ ASYNC_GENERATOR = sys .version_info [:2 ] >= (3 , 6 )
1323
1324
1324
1325
ASYNCIO_TESTS = """
1325
1326
import asyncio
@@ -1696,6 +1697,23 @@ def test_no_generator_instantiation(self):
1696
1697
with self .assertRaises (TypeError ):
1697
1698
typing .Generator [int , int , int ]()
1698
1699
1700
+ @skipUnless (PY36 , 'Python 3.6 required' )
1701
+ def test_async_generator (self ):
1702
+ ns = {}
1703
+ exec ("async def f():\n "
1704
+ " yield 42\n " , globals (), ns )
1705
+ g = ns ['f' ]()
1706
+ self .assertIsSubclass (type (g ), typing .AsyncGenerator )
1707
+
1708
+ @skipUnless (PY36 , 'Python 3.6 required' )
1709
+ def test_no_async_generator_instantiation (self ):
1710
+ with self .assertRaises (TypeError ):
1711
+ typing .AsyncGenerator ()
1712
+ with self .assertRaises (TypeError ):
1713
+ typing .AsyncGenerator [T , T ]()
1714
+ with self .assertRaises (TypeError ):
1715
+ typing .AsyncGenerator [int , int ]()
1716
+
1699
1717
def test_subclassing (self ):
1700
1718
1701
1719
class MMA (typing .MutableMapping ):
@@ -1765,6 +1783,18 @@ def g(): yield 0
1765
1783
self .assertIsSubclass (G , collections .Iterable )
1766
1784
self .assertNotIsSubclass (type (g ), G )
1767
1785
1786
+ @skipUnless (PY36 , 'Python 3.6 required' )
1787
+ def test_subclassing_async_generator (self ):
1788
+ class G (typing .AsyncGenerator [int , int ]): ...
1789
+ ns = {}
1790
+ exec ('async def g(): yield 0' , globals (), ns )
1791
+ g = ns ['g' ]
1792
+ self .assertIsSubclass (G , typing .AsyncGenerator )
1793
+ self .assertIsSubclass (G , typing .AsyncIterable )
1794
+ self .assertIsSubclass (G , collections .AsyncGenerator )
1795
+ self .assertIsSubclass (G , collections .AsyncIterable )
1796
+ self .assertNotIsSubclass (type (g ), G )
1797
+
1768
1798
def test_subclassing_subclasshook (self ):
1769
1799
1770
1800
class Base (typing .Iterable ):
0 commit comments