mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] typing tests: remove some unnecessary uses of exec()
(GH-119005) (#119039)
(cherry picked from commit a9328e2b6e
)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
56cc026c85
commit
4695f1a364
1 changed files with 9 additions and 19 deletions
|
@ -6635,24 +6635,16 @@ class CollectionsAbcTests(BaseTestCase):
|
||||||
self.assertNotIsInstance(42, typing.Iterator)
|
self.assertNotIsInstance(42, typing.Iterator)
|
||||||
|
|
||||||
def test_awaitable(self):
|
def test_awaitable(self):
|
||||||
ns = {}
|
async def foo() -> typing.Awaitable[int]:
|
||||||
exec(
|
return await AwaitableWrapper(42)
|
||||||
"async def foo() -> typing.Awaitable[int]:\n"
|
|
||||||
" return await AwaitableWrapper(42)\n",
|
|
||||||
globals(), ns)
|
|
||||||
foo = ns['foo']
|
|
||||||
g = foo()
|
g = foo()
|
||||||
self.assertIsInstance(g, typing.Awaitable)
|
self.assertIsInstance(g, typing.Awaitable)
|
||||||
self.assertNotIsInstance(foo, typing.Awaitable)
|
self.assertNotIsInstance(foo, typing.Awaitable)
|
||||||
g.send(None) # Run foo() till completion, to avoid warning.
|
g.send(None) # Run foo() till completion, to avoid warning.
|
||||||
|
|
||||||
def test_coroutine(self):
|
def test_coroutine(self):
|
||||||
ns = {}
|
async def foo():
|
||||||
exec(
|
return
|
||||||
"async def foo():\n"
|
|
||||||
" return\n",
|
|
||||||
globals(), ns)
|
|
||||||
foo = ns['foo']
|
|
||||||
g = foo()
|
g = foo()
|
||||||
self.assertIsInstance(g, typing.Coroutine)
|
self.assertIsInstance(g, typing.Coroutine)
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
|
@ -6926,10 +6918,9 @@ class CollectionsAbcTests(BaseTestCase):
|
||||||
typing.Generator[int, int, int]()
|
typing.Generator[int, int, int]()
|
||||||
|
|
||||||
def test_async_generator(self):
|
def test_async_generator(self):
|
||||||
ns = {}
|
async def f():
|
||||||
exec("async def f():\n"
|
yield 42
|
||||||
" yield 42\n", globals(), ns)
|
g = f()
|
||||||
g = ns['f']()
|
|
||||||
self.assertIsSubclass(type(g), typing.AsyncGenerator)
|
self.assertIsSubclass(type(g), typing.AsyncGenerator)
|
||||||
|
|
||||||
def test_no_async_generator_instantiation(self):
|
def test_no_async_generator_instantiation(self):
|
||||||
|
@ -7016,9 +7007,8 @@ class CollectionsAbcTests(BaseTestCase):
|
||||||
def athrow(self, typ, val=None, tb=None):
|
def athrow(self, typ, val=None, tb=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
ns = {}
|
async def g(): yield 0
|
||||||
exec('async def g(): yield 0', globals(), ns)
|
|
||||||
g = ns['g']
|
|
||||||
self.assertIsSubclass(G, typing.AsyncGenerator)
|
self.assertIsSubclass(G, typing.AsyncGenerator)
|
||||||
self.assertIsSubclass(G, typing.AsyncIterable)
|
self.assertIsSubclass(G, typing.AsyncIterable)
|
||||||
self.assertIsSubclass(G, collections.abc.AsyncGenerator)
|
self.assertIsSubclass(G, collections.abc.AsyncGenerator)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue