From e8013fd80893cdc99c70da2d3fe54ac6e24d41f8 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 26 May 2017 08:37:39 -0700 Subject: [PATCH] add types.AsyncGeneratorType (#1322) --- stdlib/3/types.pyi | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 084a1b46e..4340d8c0b 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -5,8 +5,8 @@ import sys from typing import ( - Any, Callable, Dict, Generic, Iterator, Mapping, Optional, Tuple, TypeVar, - Union, overload + Any, Awaitable, Callable, Dict, Generic, Iterator, Mapping, Optional, Tuple, TypeVar, + Union, overload, Type ) # ModuleType is exported from this module, but for circular import @@ -14,6 +14,8 @@ from typing import ( from _importlib_modulespec import ModuleType as ModuleType # Exported _T = TypeVar('_T') +_T_co = TypeVar('_T_co', covariant=True) +_T_contra = TypeVar('_T_contra', contravariant=True) _KT = TypeVar('_KT') _VT = TypeVar('_VT') @@ -92,6 +94,21 @@ class GeneratorType: @overload def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ... +if sys.version_info >= (3, 6): + class AsyncGeneratorType(Generic[_T_co, _T_contra]): + ag_await: Optional[Awaitable[Any]] + ag_frame: FrameType + ag_running: bool + ag_code: CodeType + def __aiter__(self) -> Awaitable[AsyncGeneratorType[_T_co, _T_contra]]: ... + def __anext__(self) -> Awaitable[_T_co]: ... + def asend(self, val: _T_contra) -> Awaitable[_T_co]: ... + @overload + def athrow(self, val: BaseException) -> Awaitable[_T_co]: ... + @overload + def athrow(self, typ: Type[BaseException], val: BaseException, tb: TracebackType = ...) -> Awaitable[_T_co]: ... + def aclose(self) -> Awaitable[_T_co]: ... + class CoroutineType: cr_await = ... # type: Optional[Any] cr_code = ... # type: CodeType