@@ -1320,24 +1320,18 @@ def test_isinstance_collections(self):
1320
1320
issubclass (collections .Counter , typing_extensions .Counter [str ])
1321
1321
1322
1322
def test_awaitable (self ):
1323
- ns = {}
1324
- exec (
1325
- "async def foo() -> typing_extensions.Awaitable[int]:\n "
1326
- " return await AwaitableWrapper(42)\n " ,
1327
- globals (), ns )
1328
- foo = ns ['foo' ]
1323
+ async def foo () -> typing_extensions .Awaitable [int ]:
1324
+ return await AwaitableWrapper (42 )
1325
+
1329
1326
g = foo ()
1330
1327
self .assertIsInstance (g , typing_extensions .Awaitable )
1331
1328
self .assertNotIsInstance (foo , typing_extensions .Awaitable )
1332
1329
g .send (None ) # Run foo() till completion, to avoid warning.
1333
1330
1334
1331
def test_coroutine (self ):
1335
- ns = {}
1336
- exec (
1337
- "async def foo():\n "
1338
- " return\n " ,
1339
- globals (), ns )
1340
- foo = ns ['foo' ]
1332
+ async def foo ():
1333
+ return
1334
+
1341
1335
g = foo ()
1342
1336
self .assertIsInstance (g , typing_extensions .Coroutine )
1343
1337
with self .assertRaises (TypeError ):
@@ -1457,10 +1451,10 @@ class MyCounter(typing_extensions.Counter[int]):
1457
1451
self .assertIsInstance (d , typing_extensions .Counter )
1458
1452
1459
1453
def test_async_generator (self ):
1460
- ns = {}
1461
- exec ( "async def f(): \n "
1462
- " yield 42 \n " , globals (), ns )
1463
- g = ns [ 'f' ] ()
1454
+ async def f ():
1455
+ yield 42
1456
+
1457
+ g = f ()
1464
1458
self .assertIsSubclass (type (g ), typing_extensions .AsyncGenerator )
1465
1459
1466
1460
def test_no_async_generator_instantiation (self ):
@@ -1478,9 +1472,8 @@ def asend(self, value):
1478
1472
def athrow (self , typ , val = None , tb = None ):
1479
1473
pass
1480
1474
1481
- ns = {}
1482
- exec ('async def g(): yield 0' , globals (), ns )
1483
- g = ns ['g' ]
1475
+ async def g (): yield 0
1476
+
1484
1477
self .assertIsSubclass (G , typing_extensions .AsyncGenerator )
1485
1478
self .assertIsSubclass (G , typing_extensions .AsyncIterable )
1486
1479
self .assertIsSubclass (G , collections .abc .AsyncGenerator )
0 commit comments