Skip to content

Remove some unnecessary exec()s in the test suite #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions src/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,24 +1320,18 @@ def test_isinstance_collections(self):
issubclass(collections.Counter, typing_extensions.Counter[str])

def test_awaitable(self):
ns = {}
exec(
"async def foo() -> typing_extensions.Awaitable[int]:\n"
" return await AwaitableWrapper(42)\n",
globals(), ns)
foo = ns['foo']
async def foo() -> typing_extensions.Awaitable[int]:
return await AwaitableWrapper(42)

g = foo()
self.assertIsInstance(g, typing_extensions.Awaitable)
self.assertNotIsInstance(foo, typing_extensions.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_extensions.Coroutine)
with self.assertRaises(TypeError):
Expand Down Expand Up @@ -1457,10 +1451,10 @@ class MyCounter(typing_extensions.Counter[int]):
self.assertIsInstance(d, typing_extensions.Counter)

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_extensions.AsyncGenerator)

def test_no_async_generator_instantiation(self):
Expand All @@ -1478,9 +1472,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_extensions.AsyncGenerator)
self.assertIsSubclass(G, typing_extensions.AsyncIterable)
self.assertIsSubclass(G, collections.abc.AsyncGenerator)
Expand Down