From 7206e4175ead4a82b335a8b90b970e8b3453ea14 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Fri, 19 Jan 2024 12:04:24 +0300 Subject: [PATCH] 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``.