Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 041cc2a

Browse filesBrowse files
[3.13] typing tests: remove some unnecessary uses of exec() (GH-119005) (#119038)
(cherry picked from commit a9328e2) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 54839f0 commit 041cc2a
Copy full SHA for 041cc2a

File tree

1 file changed

+9
-19
lines changed
Filter options

1 file changed

+9
-19
lines changed

‎Lib/test/test_typing.py

Copy file name to clipboardExpand all lines: Lib/test/test_typing.py
+9-19Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7060,24 +7060,16 @@ def test_iterator(self):
70607060
self.assertNotIsInstance(42, typing.Iterator)
70617061

70627062
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)
70697065
g = foo()
70707066
self.assertIsInstance(g, typing.Awaitable)
70717067
self.assertNotIsInstance(foo, typing.Awaitable)
70727068
g.send(None) # Run foo() till completion, to avoid warning.
70737069

70747070
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
70817073
g = foo()
70827074
self.assertIsInstance(g, typing.Coroutine)
70837075
with self.assertRaises(TypeError):
@@ -7362,10 +7354,9 @@ def test_no_generator_instantiation(self):
73627354
typing.Generator[int, int, int]()
73637355

73647356
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()
73697360
self.assertIsSubclass(type(g), typing.AsyncGenerator)
73707361

73717362
def test_no_async_generator_instantiation(self):
@@ -7452,9 +7443,8 @@ def asend(self, value):
74527443
def athrow(self, typ, val=None, tb=None):
74537444
pass
74547445

7455-
ns = {}
7456-
exec('async def g(): yield 0', globals(), ns)
7457-
g = ns['g']
7446+
async def g(): yield 0
7447+
74587448
self.assertIsSubclass(G, typing.AsyncGenerator)
74597449
self.assertIsSubclass(G, typing.AsyncIterable)
74607450
self.assertIsSubclass(G, collections.abc.AsyncGenerator)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.