https://github.com/python/cpython/commit/a9328e2b6ee05c186dcc552feb92b862b4a574df
commit: a9328e2b6ee05c186dcc552feb92b862b4a574df
branch: main
author: Alex Waygood <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2024-05-14T07:16:14-07:00
summary:
typing tests: remove some unnecessary uses of `exec()` (#119005)
files:
M Lib/test/test_typing.py
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index f10b0aea3cd7b9..64c4c497eb8934 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -7060,24 +7060,16 @@ def test_iterator(self):
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):
@@ -7352,10 +7344,9 @@ def test_no_generator_instantiation(self):
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):
@@ -7442,9 +7433,8 @@ def asend(self, value):
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)
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]