mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 14:01:55 +08:00
inspect, asyncio: Use more TypeGuards (#8057)
This commit is contained in:
@@ -1,21 +1,28 @@
|
||||
import sys
|
||||
from collections.abc import Coroutine
|
||||
from typing import Any
|
||||
from typing_extensions import TypeGuard
|
||||
from collections.abc import Awaitable, Callable, Coroutine
|
||||
from typing import Any, TypeVar, overload
|
||||
from typing_extensions import ParamSpec, TypeGuard
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
__all__ = ("iscoroutinefunction", "iscoroutine")
|
||||
else:
|
||||
__all__ = ("coroutine", "iscoroutinefunction", "iscoroutine")
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_FunctionT = TypeVar("_FunctionT", bound=Callable[..., Any])
|
||||
_P = ParamSpec("_P")
|
||||
|
||||
if sys.version_info < (3, 11):
|
||||
from collections.abc import Callable
|
||||
from typing import TypeVar
|
||||
def coroutine(func: _FunctionT) -> _FunctionT: ...
|
||||
|
||||
_F = TypeVar("_F", bound=Callable[..., Any])
|
||||
def coroutine(func: _F) -> _F: ...
|
||||
|
||||
def iscoroutinefunction(func: object) -> bool: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ...
|
||||
|
||||
# Can actually be a generator-style coroutine on Python 3.7
|
||||
def iscoroutine(obj: object) -> TypeGuard[Coroutine[Any, Any, Any]]: ...
|
||||
|
||||
Reference in New Issue
Block a user