mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #28556: updates to typing.py (add Coroutine, prohibit Generic[T]())
This commit is contained in:
parent
b7dedc89f1
commit
62fe1bb983
2 changed files with 45 additions and 9 deletions
|
@ -517,6 +517,9 @@ class GenericTests(BaseTestCase):
|
|||
Y[str, str]
|
||||
|
||||
def test_generic_errors(self):
|
||||
T = TypeVar('T')
|
||||
with self.assertRaises(TypeError):
|
||||
Generic[T]()
|
||||
with self.assertRaises(TypeError):
|
||||
isinstance([], List[int])
|
||||
with self.assertRaises(TypeError):
|
||||
|
@ -1255,7 +1258,7 @@ ASYNCIO = sys.version_info[:2] >= (3, 5)
|
|||
ASYNCIO_TESTS = """
|
||||
import asyncio
|
||||
|
||||
T_a = TypeVar('T')
|
||||
T_a = TypeVar('T_a')
|
||||
|
||||
class AwaitableWrapper(typing.Awaitable[T_a]):
|
||||
|
||||
|
@ -1403,6 +1406,24 @@ class CollectionsAbcTests(BaseTestCase):
|
|||
self.assertNotIsInstance(foo, typing.Awaitable)
|
||||
g.send(None) # Run foo() till completion, to avoid warning.
|
||||
|
||||
@skipUnless(ASYNCIO, 'Python 3.5 and multithreading required')
|
||||
def test_coroutine(self):
|
||||
ns = {}
|
||||
exec(
|
||||
"async def foo():\n"
|
||||
" return\n",
|
||||
globals(), ns)
|
||||
foo = ns['foo']
|
||||
g = foo()
|
||||
self.assertIsInstance(g, typing.Coroutine)
|
||||
with self.assertRaises(TypeError):
|
||||
isinstance(g, typing.Coroutine[int])
|
||||
self.assertNotIsInstance(foo, typing.Coroutine)
|
||||
try:
|
||||
g.send(None)
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
@skipUnless(ASYNCIO, 'Python 3.5 and multithreading required')
|
||||
def test_async_iterable(self):
|
||||
base_it = range(10) # type: Iterator[int]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue