summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-05-14 14:51:08 (GMT)
committerGitHub <noreply@github.com>2024-05-14 14:51:08 (GMT)
commit4695f1a364e52bafbebcfe47dee931b3ca1b7782 (patch)
treee59f765fd9738dc1aaad8457534fe769eb6ea909
parent56cc026c85c9962b610a9fd19de4ceda50cfa2e5 (diff)
downloadcpython-4695f1a364e52bafbebcfe47dee931b3ca1b7782.zip
cpython-4695f1a364e52bafbebcfe47dee931b3ca1b7782.tar.gz
cpython-4695f1a364e52bafbebcfe47dee931b3ca1b7782.tar.bz2
[3.12] typing tests: remove some unnecessary uses of `exec()` (GH-119005) (#119039)
(cherry picked from commit a9328e2b6ee05c186dcc552feb92b862b4a574df) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
-rw-r--r--Lib/test/test_typing.py28
1 files changed, 9 insertions, 19 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index ffb1425..4cf8d49 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -6635,24 +6635,16 @@ class CollectionsAbcTests(BaseTestCase):
self.assertNotIsInstance(42, typing.Iterator)
def test_awaitable(self):
- ns = {}
- exec(
- "async def foo() -> typing.Awaitable[int]:\n"
- " return await AwaitableWrapper(42)\n",
- globals(), ns)
- foo = ns['foo']
+ async def foo() -> typing.Awaitable[int]:
+ return await AwaitableWrapper(42)
g = foo()
self.assertIsInstance(g, typing.Awaitable)
self.assertNotIsInstance(foo, typing.Awaitable)
g.send(None) # Run foo() till completion, to avoid warning.
def test_coroutine(self):
- ns = {}
- exec(
- "async def foo():\n"
- " return\n",
- globals(), ns)
- foo = ns['foo']
+ async def foo():
+ return
g = foo()
self.assertIsInstance(g, typing.Coroutine)
with self.assertRaises(TypeError):
@@ -6926,10 +6918,9 @@ class CollectionsAbcTests(BaseTestCase):
typing.Generator[int, int, int]()
def test_async_generator(self):
- ns = {}
- exec("async def f():\n"
- " yield 42\n", globals(), ns)
- g = ns['f']()
+ async def f():
+ yield 42
+ g = f()
self.assertIsSubclass(type(g), typing.AsyncGenerator)
def test_no_async_generator_instantiation(self):
@@ -7016,9 +7007,8 @@ class CollectionsAbcTests(BaseTestCase):
def athrow(self, typ, val=None, tb=None):
pass
- ns = {}
- exec('async def g(): yield 0', globals(), ns)
- g = ns['g']
+ async def g(): yield 0
+
self.assertIsSubclass(G, typing.AsyncGenerator)
self.assertIsSubclass(G, typing.AsyncIterable)
self.assertIsSubclass(G, collections.abc.AsyncGenerator)