Skip to content

Commit bf827dc

Browse files
ilevkivskyigvanrossum
authored andcommitted
[WIP] Add Coroutine ABC to PEP 484 (#125)
* Simpler example for Coroutine
1 parent a978d2c commit bf827dc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pep-0484.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,20 @@ type of ``await`` expression, not to the coroutine type::
12541254
async def foo() -> None:
12551255
bar = await spam(42) # type: str
12561256

1257-
The ``typing.py`` module also provides generic ABCs ``Awaitable``,
1257+
The ``typing.py`` module provides a generic version of ABC
1258+
``collections.abc.Coroutine`` to specify awaitables that also support
1259+
``send()`` and ``throw()`` methods. The variance and order of type variables
1260+
correspond to those of ``Generator``, namely ``Coroutine[T_co, T_contra, V_co]``,
1261+
for example::
1262+
1263+
from typing import List, Coroutine
1264+
c = None # type: Coroutine[List[str], str, int]
1265+
...
1266+
x = c.send('hi') # type: List[str]
1267+
async def bar(): -> None:
1268+
x = await c # type: int
1269+
1270+
The module also provides generic ABCs ``Awaitable``,
12581271
``AsyncIterable``, and ``AsyncIterator`` for situations where more precise
12591272
types cannot be specified::
12601273

@@ -1768,10 +1781,14 @@ Generic variants of container ABCs (and a few non-containers):
17681781

17691782
* Callable (see above, listed here for completeness)
17701783

1784+
* Collection
1785+
17711786
* Container
17721787

17731788
* ContextManager
17741789

1790+
* Coroutine
1791+
17751792
* Generator, used as ``Generator[yield_type, send_type,
17761793
return_type]``. This represents the return value of generator
17771794
functions. It is a subtype of ``Iterable`` and it has additional

0 commit comments

Comments
 (0)