From 53014497c410473b24e491f5f551536e023982be Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 4 Nov 2016 11:46:50 -0700 Subject: [PATCH] Add Coroutine. Fix signature for Generator.throw(). (#656) --- stdlib/3/typing.pyi | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index f59df6519..5f232656e 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -102,7 +102,9 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): def send(self, value: _T_contra) -> _T_co:... @abstractmethod - def throw(self, typ: BaseException, val: Any = None, tb: Any = None) -> None:... + def throw(self, typ: Type[BaseException], val: Optional[BaseException] = None, + # TODO: tb should be TracebackType but that's defined in types + tb: Any = None) -> None:... @abstractmethod def close(self) -> None:... @@ -110,10 +112,27 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): @abstractmethod def __iter__(self) -> 'Generator[_T_co, _T_contra, _V_co]': ... +# TODO: Several types should only be defined if sys.python_version >= (3, 5): +# Awaitable, AsyncIterator, AsyncIterable, Coroutine, Collection, ContextManager. +# See https://github.com/python/typeshed/issues/655 for why this is not easy. + class Awaitable(Generic[_T_co]): @abstractmethod def __await__(self) -> Generator[Any, None, _T_co]:... +class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]): + @abstractmethod + def send(self, value: _T_contra) -> _T_co:... + + @abstractmethod + def throw(self, typ: Type[BaseException], val: Optional[BaseException] = None, + # TODO: tb should be TracebackType but that's defined in types + tb: Any = None) -> None:... + + @abstractmethod + def close(self) -> None:... + + # NOTE: This type does not exist in typing.py or PEP 484. # The parameters corrrespond to Generator, but the 4th is the original type. class AwaitableGenerator(Generator[_T_co, _T_contra, _V_co], Awaitable[_T_co],