From 7206e4175ead4a82b335a8b90b970e8b3453ea14 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Fri, 19 Jan 2024 12:04:24 +0300 Subject: [PATCH 1/3] gh-114281: Improve type hints in `asyncio/staggered.py` --- Lib/asyncio/staggered.py | 17 +++++++++-------- ...24-01-19-12-05-22.gh-issue-114281.H5JQe4.rst | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-01-19-12-05-22.gh-issue-114281.H5JQe4.rst diff --git a/Lib/asyncio/staggered.py b/Lib/asyncio/staggered.py index 451a53a16f3831..4605fefb530d62 100644 --- a/Lib/asyncio/staggered.py +++ b/Lib/asyncio/staggered.py @@ -3,7 +3,8 @@ __all__ = 'staggered_race', import contextlib -import typing +from collections.abc import Awaitable, Callable, Iterable +from typing import Any from . import events from . import exceptions as exceptions_mod @@ -12,14 +13,14 @@ async def staggered_race( - coro_fns: typing.Iterable[typing.Callable[[], typing.Awaitable]], - delay: typing.Optional[float], + coro_fns: Iterable[Callable[[], Awaitable[Any]]], + delay: float | None, *, - loop: events.AbstractEventLoop = None, -) -> typing.Tuple[ - typing.Any, - typing.Optional[int], - typing.List[typing.Optional[Exception]] + loop: events.AbstractEventLoop | None = None, +) -> tuple[ + Any, + int | None, + list[Exception | None] ]: """Run coroutines with staggered start times and take the first to finish. diff --git a/Misc/NEWS.d/next/Library/2024-01-19-12-05-22.gh-issue-114281.H5JQe4.rst b/Misc/NEWS.d/next/Library/2024-01-19-12-05-22.gh-issue-114281.H5JQe4.rst new file mode 100644 index 00000000000000..a50c5b14ba0111 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-01-19-12-05-22.gh-issue-114281.H5JQe4.rst @@ -0,0 +1 @@ +Improve type hints in ``Lib/asyncio/staggered.py``. From 2ea1eda62b471a6e072e269ae4f74653e47f9714 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 20 Jan 2024 10:42:31 +0300 Subject: [PATCH 2/3] Remove type annotations from `asyncio.staggered` --- Lib/asyncio/staggered.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Lib/asyncio/staggered.py b/Lib/asyncio/staggered.py index 4605fefb530d62..e180cde0243b15 100644 --- a/Lib/asyncio/staggered.py +++ b/Lib/asyncio/staggered.py @@ -3,8 +3,6 @@ __all__ = 'staggered_race', import contextlib -from collections.abc import Awaitable, Callable, Iterable -from typing import Any from . import events from . import exceptions as exceptions_mod @@ -12,16 +10,7 @@ from . import tasks -async def staggered_race( - coro_fns: Iterable[Callable[[], Awaitable[Any]]], - delay: float | None, - *, - loop: events.AbstractEventLoop | None = None, -) -> tuple[ - Any, - int | None, - list[Exception | None] -]: +async def staggered_race(coro_fns, delay, *, loop=None): """Run coroutines with staggered start times and take the first to finish. This method takes an iterable of coroutine functions. The first one is From 81f0ab8575f7af231db9f77a2a12db7c4909b0d4 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Sat, 20 Jan 2024 14:47:34 +0300 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Library/2024-01-19-12-05-22.gh-issue-114281.H5JQe4.rst Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- .../Library/2024-01-19-12-05-22.gh-issue-114281.H5JQe4.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-01-19-12-05-22.gh-issue-114281.H5JQe4.rst b/Misc/NEWS.d/next/Library/2024-01-19-12-05-22.gh-issue-114281.H5JQe4.rst index a50c5b14ba0111..36c54e8faf214c 100644 --- a/Misc/NEWS.d/next/Library/2024-01-19-12-05-22.gh-issue-114281.H5JQe4.rst +++ b/Misc/NEWS.d/next/Library/2024-01-19-12-05-22.gh-issue-114281.H5JQe4.rst @@ -1 +1,3 @@ -Improve type hints in ``Lib/asyncio/staggered.py``. +Remove type hints from ``Lib/asyncio/staggered.py``. +The annotations in the `typeshed `__ +project should be used instead.