mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 04:34:28 +08:00
add TypeGuard to coroutines.iscoroutine (#6105)
make CoroutineType extend Coroutine
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
from typing import Any, Callable, TypeVar
|
||||
import sys
|
||||
import types
|
||||
from collections.abc import Callable, Coroutine
|
||||
from typing import Any, TypeVar
|
||||
from typing_extensions import TypeGuard
|
||||
|
||||
_F = TypeVar("_F", bound=Callable[..., Any])
|
||||
|
||||
def coroutine(func: _F) -> _F: ...
|
||||
def iscoroutinefunction(func: object) -> bool: ...
|
||||
def iscoroutine(obj: object) -> bool: ...
|
||||
|
||||
if sys.version_info < (3, 8):
|
||||
def iscoroutine(obj: object) -> TypeGuard[types.GeneratorType[Any, Any, Any] | Coroutine[Any, Any, Any]]: ...
|
||||
|
||||
else:
|
||||
def iscoroutine(obj: object) -> TypeGuard[Coroutine[Any, Any, Any]]: ...
|
||||
|
||||
@@ -62,7 +62,7 @@ else:
|
||||
def iscoroutinefunction(object: object) -> bool: ...
|
||||
|
||||
def isgenerator(object: object) -> TypeGuard[GeneratorType[Any, Any, Any]]: ...
|
||||
def iscoroutine(object: object) -> TypeGuard[CoroutineType]: ...
|
||||
def iscoroutine(object: object) -> TypeGuard[CoroutineType[Any, Any, Any]]: ...
|
||||
def isawaitable(object: object) -> TypeGuard[Awaitable[Any]]: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
|
||||
@@ -6,6 +6,7 @@ from typing import (
|
||||
AsyncGenerator,
|
||||
Awaitable,
|
||||
Callable,
|
||||
Coroutine,
|
||||
Generator,
|
||||
Generic,
|
||||
ItemsView,
|
||||
@@ -211,7 +212,7 @@ class AsyncGeneratorType(AsyncGenerator[_T_co, _T_contra]):
|
||||
def aclose(self) -> Awaitable[None]: ...
|
||||
|
||||
@final
|
||||
class CoroutineType:
|
||||
class CoroutineType(Coroutine[_T_co, _T_contra, _V_co]):
|
||||
__name__: str
|
||||
__qualname__: str
|
||||
cr_await: Any | None
|
||||
@@ -219,12 +220,14 @@ class CoroutineType:
|
||||
cr_frame: FrameType
|
||||
cr_running: bool
|
||||
def close(self) -> None: ...
|
||||
def __await__(self) -> Generator[Any, None, Any]: ...
|
||||
def send(self, __arg: Any) -> Any: ...
|
||||
def __await__(self) -> Generator[Any, None, _V_co]: ...
|
||||
def send(self, __arg: _T_contra) -> _T_co: ...
|
||||
@overload
|
||||
def throw(self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...) -> Any: ...
|
||||
def throw(
|
||||
self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
|
||||
) -> _T_co: ...
|
||||
@overload
|
||||
def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> Any: ...
|
||||
def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ...
|
||||
|
||||
class _StaticFunctionType:
|
||||
"""Fictional type to correct the type of MethodType.__func__.
|
||||
@@ -365,7 +368,7 @@ def prepare_class(
|
||||
# Actually a different type, but `property` is special and we want that too.
|
||||
DynamicClassAttribute = property
|
||||
|
||||
def coroutine(func: Callable[..., Any]) -> CoroutineType: ...
|
||||
def coroutine(func: Callable[..., Any]) -> CoroutineType[Any, Any, Any]: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
CellType = _Cell
|
||||
|
||||
Reference in New Issue
Block a user