@@ -6635,24 +6635,16 @@ def test_iterator(self):
6635
6635
self .assertNotIsInstance (42 , typing .Iterator )
6636
6636
6637
6637
def test_awaitable (self ):
6638
- ns = {}
6639
- exec (
6640
- "async def foo() -> typing.Awaitable[int]:\n "
6641
- " return await AwaitableWrapper(42)\n " ,
6642
- globals (), ns )
6643
- foo = ns ['foo' ]
6638
+ async def foo () -> typing .Awaitable [int ]:
6639
+ return await AwaitableWrapper (42 )
6644
6640
g = foo ()
6645
6641
self .assertIsInstance (g , typing .Awaitable )
6646
6642
self .assertNotIsInstance (foo , typing .Awaitable )
6647
6643
g .send (None ) # Run foo() till completion, to avoid warning.
6648
6644
6649
6645
def test_coroutine (self ):
6650
- ns = {}
6651
- exec (
6652
- "async def foo():\n "
6653
- " return\n " ,
6654
- globals (), ns )
6655
- foo = ns ['foo' ]
6646
+ async def foo ():
6647
+ return
6656
6648
g = foo ()
6657
6649
self .assertIsInstance (g , typing .Coroutine )
6658
6650
with self .assertRaises (TypeError ):
@@ -6926,10 +6918,9 @@ def test_no_generator_instantiation(self):
6926
6918
typing .Generator [int , int , int ]()
6927
6919
6928
6920
def test_async_generator (self ):
6929
- ns = {}
6930
- exec ("async def f():\n "
6931
- " yield 42\n " , globals (), ns )
6932
- g = ns ['f' ]()
6921
+ async def f ():
6922
+ yield 42
6923
+ g = f ()
6933
6924
self .assertIsSubclass (type (g ), typing .AsyncGenerator )
6934
6925
6935
6926
def test_no_async_generator_instantiation (self ):
@@ -7016,9 +7007,8 @@ def asend(self, value):
7016
7007
def athrow (self , typ , val = None , tb = None ):
7017
7008
pass
7018
7009
7019
- ns = {}
7020
- exec ('async def g(): yield 0' , globals (), ns )
7021
- g = ns ['g' ]
7010
+ async def g (): yield 0
7011
+
7022
7012
self .assertIsSubclass (G , typing .AsyncGenerator )
7023
7013
self .assertIsSubclass (G , typing .AsyncIterable )
7024
7014
self .assertIsSubclass (G , collections .abc .AsyncGenerator )
0 commit comments