From 7f22db04921b3ebcaf1a6729f7c82cbc723cb29f Mon Sep 17 00:00:00 2001 From: Roy Williams Date: Tue, 1 Dec 2015 11:38:01 -0800 Subject: [PATCH] Add Async classes to typing stub. --- stdlib/3.4/asyncio/events.pyi | 4 ++-- stdlib/3/typing.pyi | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/stdlib/3.4/asyncio/events.pyi b/stdlib/3.4/asyncio/events.pyi index 85812f2717d6..bcac004cb249 100644 --- a/stdlib/3.4/asyncio/events.pyi +++ b/stdlib/3.4/asyncio/events.pyi @@ -1,4 +1,4 @@ -from typing import Any, TypeVar, List, Callable, Tuple, Union, Dict +from typing import Any, Awaitable, TypeVar, List, Callable, Tuple, Union, Dict from abc import ABCMeta, abstractmethod from asyncio.futures import Future @@ -34,7 +34,7 @@ class AbstractEventLoop(metaclass=ABCMeta): @abstractmethod def run_forever(self) -> None: ... @abstractmethod - def run_until_complete(self, future: Future[_T]) -> _T: ... + def run_until_complete(self, future: Union[Awaitable[_T], Future[_T]]) -> _T: ... @abstractmethod def stop(self) -> None: ... @abstractmethod diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 0d411c81bc86..e638866f42e0 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -1,6 +1,7 @@ # Stubs for typing from abc import abstractmethod, ABCMeta +from asyncio.futures import Future # Definitions of special type checking related constructs. Their definition # are not used, so their value does not matter. @@ -94,7 +95,34 @@ class Iterable(Generic[_T_co]): class Iterator(Iterable[_T_co], Generic[_T_co]): @abstractmethod def __next__(self) -> _T_co: ... - def __iter__(self) -> Iterator[_T_co]: ... + def __iter__(self) -> 'Iterator[_T_co]': ... + +class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): + @abstractmethod + def __next__(self) -> _T_co:... + + @abstractmethod + def send(self, value: _T_contra) -> _T_co:... + + @abstractmethod + def throw(self, typ: BaseException, val: Any=None, tb=None) -> None:... + + @abstractmethod + def close(self) -> None:... + +class Awaitable(Generic[_T_co]): + @abstractmethod + def __await__(self) -> Generator[Future, Any, _T_co]:... + +class AsyncIterable(Generic[_T_co]): + @abstractmethod + def __anext__(self) -> Awaitable[_T_co]:... + +class AsyncIterator(AsyncIterable[_T_co], + Generic[_T_co]): + @abstractmethod + def __anext__(self) -> Awaitable[_T_co]:... + def __aiter__(self) -> 'AsyncIterator[_T_co]':... class Container(Generic[_T_co]): @abstractmethod