[WIP] Add Coroutine ABC to PEP 484 (#125)
* Simpler example for Coroutine
This commit is contained in:
parent
a978d2cbb0
commit
bf827dc23d
19
pep-0484.txt
19
pep-0484.txt
|
@ -1254,7 +1254,20 @@ type of ``await`` expression, not to the coroutine type::
|
|||
async def foo() -> None:
|
||||
bar = await spam(42) # type: str
|
||||
|
||||
The ``typing.py`` module also provides generic ABCs ``Awaitable``,
|
||||
The ``typing.py`` module provides a generic version of ABC
|
||||
``collections.abc.Coroutine`` to specify awaitables that also support
|
||||
``send()`` and ``throw()`` methods. The variance and order of type variables
|
||||
correspond to those of ``Generator``, namely ``Coroutine[T_co, T_contra, V_co]``,
|
||||
for example::
|
||||
|
||||
from typing import List, Coroutine
|
||||
c = None # type: Coroutine[List[str], str, int]
|
||||
...
|
||||
x = c.send('hi') # type: List[str]
|
||||
async def bar(): -> None:
|
||||
x = await c # type: int
|
||||
|
||||
The module also provides generic ABCs ``Awaitable``,
|
||||
``AsyncIterable``, and ``AsyncIterator`` for situations where more precise
|
||||
types cannot be specified::
|
||||
|
||||
|
@ -1768,10 +1781,14 @@ Generic variants of container ABCs (and a few non-containers):
|
|||
|
||||
* Callable (see above, listed here for completeness)
|
||||
|
||||
* Collection
|
||||
|
||||
* Container
|
||||
|
||||
* ContextManager
|
||||
|
||||
* Coroutine
|
||||
|
||||
* Generator, used as ``Generator[yield_type, send_type,
|
||||
return_type]``. This represents the return value of generator
|
||||
functions. It is a subtype of ``Iterable`` and it has additional
|
||||
|
|
Loading…
Reference in New Issue