From a10177cfacd056017a3715967fde4c9ee40cc39f Mon Sep 17 00:00:00 2001 From: jrheard Date: Wed, 2 Apr 2025 14:52:02 -0700 Subject: [PATCH] #3142: Improve usability of multi() and multi_future() type annotations --- tornado/gen.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tornado/gen.py b/tornado/gen.py index d12f32fb..e818e10c 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -91,7 +91,18 @@ except ImportError: contextvars = None # type: ignore import typing -from typing import Union, Any, Callable, List, Type, Tuple, Awaitable, Dict, overload +from typing import ( + Mapping, + Union, + Any, + Callable, + List, + Type, + Tuple, + Awaitable, + Dict, + overload, +) if typing.TYPE_CHECKING: from typing import Sequence, Deque, Optional, Set, Iterable # noqa: F401 @@ -426,7 +437,7 @@ class WaitIterator: def multi( - children: Union[List[_Yieldable], Dict[Any, _Yieldable]], + children: Union[Sequence[_Yieldable], Mapping[Any, _Yieldable]], quiet_exceptions: "Union[Type[Exception], Tuple[Type[Exception], ...]]" = (), ) -> "Union[Future[List], Future[Dict]]": """Runs multiple asynchronous operations in parallel. @@ -480,7 +491,7 @@ Multi = multi def multi_future( - children: Union[List[_Yieldable], Dict[Any, _Yieldable]], + children: Union[Sequence[_Yieldable], Mapping[Any, _Yieldable]], quiet_exceptions: "Union[Type[Exception], Tuple[Type[Exception], ...]]" = (), ) -> "Union[Future[List], Future[Dict]]": """Wait for multiple asynchronous futures in parallel. -- 2.47.2