From 79ffec03754a58ecd20eb00748ab13ae82ffc2d2 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 7 Jan 2017 13:07:41 -0800 Subject: [PATCH 1/3] add AsyncGenerator to typing.pyi This parallels https://github.com/python/typing/pull/346 --- stdlib/3/typing.pyi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 554852669f2d..cf9211bd9357 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -151,6 +151,24 @@ class AsyncIterator(AsyncIterable[_T_co], def __anext__(self) -> Awaitable[_T_co]: ... def __aiter__(self) -> 'AsyncIterator[_T_co]': ... +if sys.version_info >= (3, 6): + class AsyncGenerator(AsyncIterator[_T_co], Generic[_T_co, _T_contra]): + @abstractmethod + def __anext__(self) -> Awaitable[_T_co]: ... + + @abstractmethod + def asend(self, value: _T_contra) -> Awaitable[_T_co]: ... + + @abstractmethod + def athrow(self, typ: Type[BaseException], val: Optional[BaseException] = None, + tb: Any = None) -> Awaitable[None]: ... + + @abstractmethod + def aclose(self) -> Awaitable[None]: ... + + @abstractmethod + def __aiter__(self) -> 'AsyncGenerator[_T_co, _T_contra]': ... + class Container(Generic[_T_co]): @abstractmethod def __contains__(self, x: object) -> bool: ... From b0487a6e0af9f4f2b95764d38c9db09d9bf1a68d Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 18 Jan 2017 13:17:36 -0800 Subject: [PATCH 2/3] also add AsyncGenerator to collections and collections.abc --- stdlib/3/collections/__init__.pyi | 2 ++ stdlib/3/collections/abc.pyi | 1 + 2 files changed, 3 insertions(+) diff --git a/stdlib/3/collections/__init__.pyi b/stdlib/3/collections/__init__.pyi index 00f463b5119d..e7796d9160d5 100644 --- a/stdlib/3/collections/__init__.pyi +++ b/stdlib/3/collections/__init__.pyi @@ -35,6 +35,8 @@ from typing import ( MutableSet as MutableSet, AbstractSet as Set, ) +if sys.version_info >= (3, 6): + from typing import AsyncGenerator as AsyncGenerator _T = TypeVar('_T') _KT = TypeVar('_KT') diff --git a/stdlib/3/collections/abc.pyi b/stdlib/3/collections/abc.pyi index f7d3ae4201fb..5106ec5139ee 100644 --- a/stdlib/3/collections/abc.pyi +++ b/stdlib/3/collections/abc.pyi @@ -35,4 +35,5 @@ if sys.version_info >= (3, 5): if sys.version_info >= (3, 6): from . import ( Reversible as Reversible, + AsyncGenerator as AsyncGenerator, ) From 410a0e214f91d9e1af7197b0021c7cadd4304e36 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 18 Jan 2017 13:20:59 -0800 Subject: [PATCH 3/3] add missing import --- stdlib/3/collections/__init__.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/3/collections/__init__.pyi b/stdlib/3/collections/__init__.pyi index e7796d9160d5..58809f85e379 100644 --- a/stdlib/3/collections/__init__.pyi +++ b/stdlib/3/collections/__init__.pyi @@ -5,6 +5,7 @@ # TODO more abstract base classes (interfaces in mypy) # These are not exported. +import sys from typing import ( TypeVar, Generic, Dict, overload, List, Tuple, Callable, Any, Type, Optional, Union