Make types.coroutine return Awaitable (#6255)

This commit is contained in:
KotlinIsland
2021-11-08 21:34:42 +10:00
committed by GitHub
parent 977a32a3c9
commit b8cbac800f

View File

@@ -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