@@ -7060,24 +7060,16 @@ def test_iterator(self):
7060
7060
self .assertNotIsInstance (42 , typing .Iterator )
7061
7061
7062
7062
def test_awaitable (self ):
7063
- ns = {}
7064
- exec (
7065
- "async def foo() -> typing.Awaitable[int]:\n "
7066
- " return await AwaitableWrapper(42)\n " ,
7067
- globals (), ns )
7068
- foo = ns ['foo' ]
7063
+ async def foo () -> typing .Awaitable [int ]:
7064
+ return await AwaitableWrapper (42 )
7069
7065
g = foo ()
7070
7066
self .assertIsInstance (g , typing .Awaitable )
7071
7067
self .assertNotIsInstance (foo , typing .Awaitable )
7072
7068
g .send (None ) # Run foo() till completion, to avoid warning.
7073
7069
7074
7070
def test_coroutine (self ):
7075
- ns = {}
7076
- exec (
7077
- "async def foo():\n "
7078
- " return\n " ,
7079
- globals (), ns )
7080
- foo = ns ['foo' ]
7071
+ async def foo ():
7072
+ return
7081
7073
g = foo ()
7082
7074
self .assertIsInstance (g , typing .Coroutine )
7083
7075
with self .assertRaises (TypeError ):
@@ -7362,10 +7354,9 @@ def test_no_generator_instantiation(self):
7362
7354
typing .Generator [int , int , int ]()
7363
7355
7364
7356
def test_async_generator (self ):
7365
- ns = {}
7366
- exec ("async def f():\n "
7367
- " yield 42\n " , globals (), ns )
7368
- g = ns ['f' ]()
7357
+ async def f ():
7358
+ yield 42
7359
+ g = f ()
7369
7360
self .assertIsSubclass (type (g ), typing .AsyncGenerator )
7370
7361
7371
7362
def test_no_async_generator_instantiation (self ):
@@ -7452,9 +7443,8 @@ def asend(self, value):
7452
7443
def athrow (self , typ , val = None , tb = None ):
7453
7444
pass
7454
7445
7455
- ns = {}
7456
- exec ('async def g(): yield 0' , globals (), ns )
7457
- g = ns ['g' ]
7446
+ async def g (): yield 0
7447
+
7458
7448
self .assertIsSubclass (G , typing .AsyncGenerator )
7459
7449
self .assertIsSubclass (G , typing .AsyncIterable )
7460
7450
self .assertIsSubclass (G , collections .abc .AsyncGenerator )
0 commit comments