@@ -1735,6 +1735,23 @@ def test_no_generator_instantiation(self):
1735
1735
with self .assertRaises (TypeError ):
1736
1736
typing .Generator [int , int , int ]()
1737
1737
1738
+ @skipUnless (PY36 , 'Python 3.6 required' )
1739
+ def test_async_generator (self ):
1740
+ ns = {}
1741
+ exec ("async def f():\n "
1742
+ " yield 42\n " , globals (), ns )
1743
+ g = ns ['f' ]()
1744
+ self .assertIsSubclass (type (g ), typing .AsyncGenerator )
1745
+
1746
+ @skipUnless (PY36 , 'Python 3.6 required' )
1747
+ def test_no_async_generator_instantiation (self ):
1748
+ with self .assertRaises (TypeError ):
1749
+ typing .AsyncGenerator ()
1750
+ with self .assertRaises (TypeError ):
1751
+ typing .AsyncGenerator [T , T ]()
1752
+ with self .assertRaises (TypeError ):
1753
+ typing .AsyncGenerator [int , int ]()
1754
+
1738
1755
def test_subclassing (self ):
1739
1756
1740
1757
class MMA (typing .MutableMapping ):
@@ -1804,6 +1821,30 @@ def g(): yield 0
1804
1821
self .assertIsSubclass (G , collections .Iterable )
1805
1822
self .assertNotIsSubclass (type (g ), G )
1806
1823
1824
+ @skipUnless (PY36 , 'Python 3.6 required' )
1825
+ def test_subclassing_async_generator (self ):
1826
+ class G (typing .AsyncGenerator [int , int ]):
1827
+ def asend (self , value ):
1828
+ pass
1829
+ def athrow (self , typ , val = None , tb = None ):
1830
+ pass
1831
+
1832
+ ns = {}
1833
+ exec ('async def g(): yield 0' , globals (), ns )
1834
+ g = ns ['g' ]
1835
+ self .assertIsSubclass (G , typing .AsyncGenerator )
1836
+ self .assertIsSubclass (G , typing .AsyncIterable )
1837
+ self .assertIsSubclass (G , collections .AsyncGenerator )
1838
+ self .assertIsSubclass (G , collections .AsyncIterable )
1839
+ self .assertNotIsSubclass (type (g ), G )
1840
+
1841
+ instance = G ()
1842
+ self .assertIsInstance (instance , typing .AsyncGenerator )
1843
+ self .assertIsInstance (instance , typing .AsyncIterable )
1844
+ self .assertIsInstance (instance , collections .AsyncGenerator )
1845
+ self .assertIsInstance (instance , collections .AsyncIterable )
1846
+ self .assertNotIsInstance (type (g ), G )
1847
+
1807
1848
def test_subclassing_subclasshook (self ):
1808
1849
1809
1850
class Base (typing .Iterable ):
0 commit comments