8000 [3.12] typing tests: remove some unnecessary uses of `exec()` (GH-119… · python/cpython@4695f1a · GitHub
[go: up one dir, main page]

Skip to content

Commit 4695f1a

Browse files
[3.12] typing tests: remove some unnecessary uses of exec() (GH-119005) (#119039)
(cherry picked from commit a9328e2) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 56cc026 commit 4695f1a

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

Lib/test/test_typing.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6635,24 +6635,16 @@ def test_iterator(self):
66356635
self.assertNotIsInstance(42, typing.Iterator)
66366636

66376637
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)
66446640
g = foo()
66456641
self.assertIsInstance(g, typing.Awaitable)
66466642
self.assertNotIsInstance(foo, typing.Awaitable)
66476643
g.send(None) # Run foo() till completion, to avoid warning.
66486644

66496645
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
66566648
g = foo()
66576649
self.assertIsInstance(g, typing.Coroutine)
66586650
with self.assertRaises(TypeError):
@@ -6926,10 +6918,9 @@ def test_no_generator_instantiation(self):
69266918
typing.Generator[int, int, int]()
69276919

69286920
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()
69336924
self.assertIsSubclass(type(g), typing.AsyncGenerator)
69346925

69356926
def test_no_async_generator_instantiation(self):
@@ -7016,9 +7007,8 @@ def asend(self, value):
70167007
def athrow(self, typ, val=None, tb=None):
70177008
pass
70187009

7019-
ns = {}
7020-
exec('async def g(): yield 0', globals(), ns)
7021-
g = ns['g']
7010+
async def g(): yield 0
7011+
70227012
self.assertIsSubclass(G, typing.AsyncGenerator)
70237013
self.assertIsSubclass(G, typing.AsyncIterable)
70247014
self.assertIsSubclass(G, collections.abc.AsyncGenerator)

0 commit comments

Comments
 (0)
0