[3.13] typing tests: remove some unnecessary uses of exec() (GH-119005) (#119038)

(cherry picked from commit a9328e2b6e)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-05-14 16:39:55 +02:00 committed by GitHub
parent 54839f0734
commit 041cc2a4be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7060,24 +7060,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):
@ -7362,10 +7354,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):
@ -7452,9 +7443,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)