diff --git a/stdlib/asyncio/base_futures.pyi b/stdlib/asyncio/base_futures.pyi index 14ec54e9c..1b7fe4671 100644 --- a/stdlib/asyncio/base_futures.pyi +++ b/stdlib/asyncio/base_futures.pyi @@ -1,6 +1,6 @@ import sys from typing import Any, Callable, Sequence -from typing_extensions import Literal, TypeGuard +from typing_extensions import Literal if sys.version_info >= (3, 7): from contextvars import Context @@ -12,12 +12,15 @@ if sys.version_info >= (3, 7): else: __all__: list[str] = [] +# asyncio defines 'isfuture()' in base_futures.py and re-imports it in futures.py +# but it leads to circular import error in pytype tool. +# That's why the import order is reversed. +from .futures import isfuture as isfuture + _PENDING: Literal["PENDING"] # undocumented _CANCELLED: Literal["CANCELLED"] # undocumented _FINISHED: Literal["FINISHED"] # undocumented -def isfuture(obj: object) -> TypeGuard[futures.Future[Any]]: ... - if sys.version_info >= (3, 7): def _format_callbacks(cb: Sequence[tuple[Callable[[futures.Future[Any]], None], Context]]) -> str: ... # undocumented diff --git a/stdlib/asyncio/futures.pyi b/stdlib/asyncio/futures.pyi index c565b504b..70eba2cd3 100644 --- a/stdlib/asyncio/futures.pyi +++ b/stdlib/asyncio/futures.pyi @@ -2,6 +2,7 @@ import sys from _typeshed import Self from concurrent.futures._base import Error, Future as _ConcurrentFuture from typing import Any, Awaitable, Callable, Generator, Iterable, TypeVar +from typing_extensions import TypeGuard from .events import AbstractEventLoop @@ -25,6 +26,11 @@ else: _T = TypeVar("_T") +# asyncio defines 'isfuture()' in base_futures.py and re-imports it in futures.py +# but it leads to circular import error in pytype tool. +# That's why the import order is reversed. +def isfuture(obj: object) -> TypeGuard[Future[Any]]: ... + if sys.version_info < (3, 7): class _TracebackLogger: exc: BaseException @@ -34,8 +40,6 @@ if sys.version_info < (3, 7): def clear(self) -> None: ... def __del__(self) -> None: ... -def isfuture(obj: object) -> bool: ... - class Future(Awaitable[_T], Iterable[_T]): _state: str _exception: BaseException