From 7620bd7bc3ad8bdc8d82bfe3aed46ca7d9854ed9 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Wed, 16 Oct 2024 12:53:03 -0700 Subject: [PATCH 1/5] remove unneeded Awaitable base class from asyncio.Future --- stdlib/_asyncio.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_asyncio.pyi b/stdlib/_asyncio.pyi index 18920cd8a8a4..2f38cf2a8262 100644 --- a/stdlib/_asyncio.pyi +++ b/stdlib/_asyncio.pyi @@ -13,7 +13,7 @@ _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) _TaskYieldType: TypeAlias = Future[object] | None -class Future(Awaitable[_T], Iterable[_T]): +class Future(Iterable[_T]): _state: str @property def _exception(self) -> BaseException | None: ... From b7e0ac93a587e55e9eec9c38d192b54569db3b9f Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Wed, 16 Oct 2024 13:08:20 -0700 Subject: [PATCH 2/5] and what if we keep awaitable but remove iterable? --- stdlib/_asyncio.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/_asyncio.pyi b/stdlib/_asyncio.pyi index 2f38cf2a8262..a259026615aa 100644 --- a/stdlib/_asyncio.pyi +++ b/stdlib/_asyncio.pyi @@ -1,6 +1,6 @@ import sys from asyncio.events import AbstractEventLoop -from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable +from collections.abc import Awaitable, Callable, Coroutine, Generator from contextvars import Context from types import FrameType from typing import Any, Literal, TextIO, TypeVar @@ -13,7 +13,7 @@ _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) _TaskYieldType: TypeAlias = Future[object] | None -class Future(Iterable[_T]): +class Future(Awaitable[_T]): _state: str @property def _exception(self) -> BaseException | None: ... From 8c5ef51b6a648d64802d9aac71d8115798704082 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Wed, 16 Oct 2024 13:28:22 -0700 Subject: [PATCH 3/5] make asyncio.Future covariant --- stdlib/_asyncio.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/_asyncio.pyi b/stdlib/_asyncio.pyi index a259026615aa..3c83817748d4 100644 --- a/stdlib/_asyncio.pyi +++ b/stdlib/_asyncio.pyi @@ -3,7 +3,7 @@ from asyncio.events import AbstractEventLoop from collections.abc import Awaitable, Callable, Coroutine, Generator from contextvars import Context from types import FrameType -from typing import Any, Literal, TextIO, TypeVar +from typing import Any, Generic, Literal, TextIO, TypeVar from typing_extensions import Self, TypeAlias if sys.version_info >= (3, 9): @@ -13,7 +13,7 @@ _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) _TaskYieldType: TypeAlias = Future[object] | None -class Future(Awaitable[_T]): +class Future(Generic[_T_co]): _state: str @property def _exception(self) -> BaseException | None: ... @@ -41,8 +41,8 @@ class Future(Awaitable[_T]): def remove_done_callback(self, fn: Callable[[Self], object], /) -> int: ... def set_result(self, result: _T, /) -> None: ... def set_exception(self, exception: type | BaseException, /) -> None: ... - def __iter__(self) -> Generator[Any, None, _T]: ... - def __await__(self) -> Generator[Any, None, _T]: ... + def __iter__(self) -> Generator[Any, None, _T_co]: ... + def __await__(self) -> Generator[Any, None, _T_co]: ... @property def _loop(self) -> AbstractEventLoop: ... if sys.version_info >= (3, 9): From 2c698b920835980eab62c361ea98f54f0bce26a6 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Wed, 16 Oct 2024 13:32:35 -0700 Subject: [PATCH 4/5] missed some --- stdlib/_asyncio.pyi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stdlib/_asyncio.pyi b/stdlib/_asyncio.pyi index 3c83817748d4..d9c62ed0eb90 100644 --- a/stdlib/_asyncio.pyi +++ b/stdlib/_asyncio.pyi @@ -9,7 +9,6 @@ from typing_extensions import Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias -_T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) _TaskYieldType: TypeAlias = Future[object] | None @@ -36,10 +35,10 @@ class Future(Generic[_T_co]): def cancelled(self) -> bool: ... def done(self) -> bool: ... - def result(self) -> _T: ... + def result(self) -> _T_co: ... def exception(self) -> BaseException | None: ... def remove_done_callback(self, fn: Callable[[Self], object], /) -> int: ... - def set_result(self, result: _T, /) -> None: ... + def set_result(self, result: _T_co, /) -> None: ... def set_exception(self, exception: type | BaseException, /) -> None: ... def __iter__(self) -> Generator[Any, None, _T_co]: ... def __await__(self) -> Generator[Any, None, _T_co]: ... From bd941819721829d6fa4a516a60c363f9f2a8169d Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Wed, 16 Oct 2024 13:50:25 -0700 Subject: [PATCH 5/5] use Awaitable again --- stdlib/_asyncio.pyi | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/stdlib/_asyncio.pyi b/stdlib/_asyncio.pyi index d9c62ed0eb90..a259026615aa 100644 --- a/stdlib/_asyncio.pyi +++ b/stdlib/_asyncio.pyi @@ -3,16 +3,17 @@ from asyncio.events import AbstractEventLoop from collections.abc import Awaitable, Callable, Coroutine, Generator from contextvars import Context from types import FrameType -from typing import Any, Generic, Literal, TextIO, TypeVar +from typing import Any, Literal, TextIO, TypeVar from typing_extensions import Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias +_T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) _TaskYieldType: TypeAlias = Future[object] | None -class Future(Generic[_T_co]): +class Future(Awaitable[_T]): _state: str @property def _exception(self) -> BaseException | None: ... @@ -35,13 +36,13 @@ class Future(Generic[_T_co]): def cancelled(self) -> bool: ... def done(self) -> bool: ... - def result(self) -> _T_co: ... + def result(self) -> _T: ... def exception(self) -> BaseException | None: ... def remove_done_callback(self, fn: Callable[[Self], object], /) -> int: ... - def set_result(self, result: _T_co, /) -> None: ... + def set_result(self, result: _T, /) -> None: ... def set_exception(self, exception: type | BaseException, /) -> None: ... - def __iter__(self) -> Generator[Any, None, _T_co]: ... - def __await__(self) -> Generator[Any, None, _T_co]: ... + def __iter__(self) -> Generator[Any, None, _T]: ... + def __await__(self) -> Generator[Any, None, _T]: ... @property def _loop(self) -> AbstractEventLoop: ... if sys.version_info >= (3, 9):