From b8cbac800f503976ed53f9168232516d799e6bf1 Mon Sep 17 00:00:00 2001 From: KotlinIsland <65446343+KotlinIsland@users.noreply.github.com> Date: Mon, 8 Nov 2021 21:34:42 +1000 Subject: [PATCH] Make types.coroutine return Awaitable (#6255) --- stdlib/types.pyi | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/stdlib/types.pyi b/stdlib/types.pyi index fe81185e7..7d738bf7e 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -21,7 +21,7 @@ from typing import ( ValuesView, overload, ) -from typing_extensions import Literal, final +from typing_extensions import Literal, ParamSpec, final # Note, all classes "defined" here require special handling. @@ -370,7 +370,15 @@ def prepare_class( # Actually a different type, but `property` is special and we want that too. DynamicClassAttribute = property -def coroutine(func: Callable[..., Any]) -> CoroutineType[Any, Any, Any]: ... +_Fn = TypeVar("_Fn", bound=Callable[..., object]) +_R = TypeVar("_R") +_P = ParamSpec("_P") + +# it's not really an Awaitable, but can be used in an await expression. Real type: Generator & Awaitable +@overload +def coroutine(func: Callable[_P, Generator[_R, Any, Any]]) -> Callable[_P, Awaitable[_R]]: ... # type: ignore +@overload +def coroutine(func: _Fn) -> _Fn: ... # type: ignore if sys.version_info >= (3, 8): CellType = _Cell