Skip to content

Commit ed09c9f

Browse files
authored
Remove some unnecessary exec()s in the test suite (#219)
1 parent 7c4bc2e commit ed09c9f

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/test_typing_extensions.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,24 +1320,18 @@ def test_isinstance_collections(self):
13201320
issubclass(collections.Counter, typing_extensions.Counter[str])
13211321

13221322
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+
13291326
g = foo()
13301327
self.assertIsInstance(g, typing_extensions.Awaitable)
13311328
self.assertNotIsInstance(foo, typing_extensions.Awaitable)
13321329
g.send(None) # Run foo() till completion, to avoid warning.
13331330

13341331
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+
13411335
g = foo()
13421336
self.assertIsInstance(g, typing_extensions.Coroutine)
13431337
with self.assertRaises(TypeError):
@@ -1457,10 +1451,10 @@ class MyCounter(typing_extensions.Counter[int]):
14571451
self.assertIsInstance(d, typing_extensions.Counter)
14581452

14591453
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()
14641458
self.assertIsSubclass(type(g), typing_extensions.AsyncGenerator)
14651459

14661460
def test_no_async_generator_instantiation(self):
@@ -1478,9 +1472,8 @@ def asend(self, value):
14781472
def athrow(self, typ, val=None, tb=None):
14791473
pass
14801474

1481-
ns = {}
1482-
exec('async def g(): yield 0', globals(), ns)
1483-
g = ns['g']
1475+
async def g(): yield 0
1476+
14841477
self.assertIsSubclass(G, typing_extensions.AsyncGenerator)
14851478
self.assertIsSubclass(G, typing_extensions.AsyncIterable)
14861479
self.assertIsSubclass(G, collections.abc.AsyncGenerator)

0 commit comments

Comments
 (0)