Skip to content

Commit c5f1e90

Browse files
LiraNunaJelleZijlstra
authored andcommitted
More precisely typehint asyncio.gather up to 5 params (#1550)
1 parent 258b9fb commit c5f1e90

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

stdlib/3.4/asyncio/tasks.pyi

+24-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ from .futures import Future
88
__all__: List[str]
99

1010
_T = TypeVar('_T')
11+
_T1 = TypeVar('_T1')
12+
_T2 = TypeVar('_T2')
13+
_T3 = TypeVar('_T3')
14+
_T4 = TypeVar('_T4')
15+
_T5 = TypeVar('_T5')
1116
_FutureT = Union[Future[_T], Generator[Any, None, _T], Awaitable[_T]]
1217

1318
FIRST_EXCEPTION = 'FIRST_EXCEPTION'
@@ -19,10 +24,25 @@ def as_completed(fs: Sequence[_FutureT[_T]], *, loop: AbstractEventLoop = ...,
1924
def ensure_future(coro_or_future: _FutureT[_T],
2025
*, loop: AbstractEventLoop = ...) -> Future[_T]: ...
2126
async = ensure_future
22-
# TODO: gather() should use variadic type vars instead of _TAny.
23-
_TAny = Any
24-
def gather(*coros_or_futures: _FutureT[_TAny],
25-
loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[List[_TAny]]: ...
27+
@overload
28+
def gather(coro_or_future1: _FutureT[_T1],
29+
*, loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[Tuple[_T1]]: ...
30+
@overload
31+
def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2],
32+
*, loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[Tuple[_T1, _T2]]: ...
33+
@overload
34+
def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3],
35+
coro_or_future4: _FutureT[_T4],
36+
*, loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[Tuple[_T1, _T2, _T3, _T4]]: ...
37+
@overload
38+
def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3],
39+
coro_or_future4: _FutureT[_T4], coro_or_future5: _FutureT[_T5],
40+
*, loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
41+
@overload
42+
def gather(coro_or_future1: _FutureT[Any], coro_or_future2: _FutureT[Any], coro_or_future3: _FutureT[Any],
43+
coro_or_future4: _FutureT[Any], coro_or_future5: _FutureT[Any], coro_or_future6: _FutureT[Any],
44+
*coros_or_futures: _FutureT[Any],
45+
loop: AbstractEventLoop = ..., return_exceptions: bool = False) -> Future[Tuple[Any, ...]]: ...
2646
def run_coroutine_threadsafe(coro: _FutureT[_T],
2747
loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...
2848
def shield(arg: _FutureT[_T], *, loop: AbstractEventLoop = ...) -> Future[_T]: ...

0 commit comments

Comments
 (0)