From 0740d1c48e48ddd426ac8cb56572ebd12a3652b1 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 21 Jun 2022 15:31:40 +0100 Subject: [PATCH] `asyncio.gather`: Add overload for if no positional arguments are provided (#8126) --- stdlib/asyncio/tasks.pyi | 50 ++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/stdlib/asyncio/tasks.pyi b/stdlib/asyncio/tasks.pyi index a130c3c1d..e20720aef 100644 --- a/stdlib/asyncio/tasks.pyi +++ b/stdlib/asyncio/tasks.pyi @@ -86,6 +86,8 @@ def ensure_future(coro_or_future: Awaitable[_T], *, loop: AbstractEventLoop | No # zip() because typing does not support variadic type variables. See # typing PR #1550 for discussion. if sys.version_info >= (3, 10): + @overload + def gather(*, return_exceptions: bool = ...) -> Future[tuple[()]]: ... @overload def gather(__coro_or_future1: _FutureT[_T1], *, return_exceptions: Literal[False] = ...) -> Future[tuple[_T1]]: ... @overload @@ -120,17 +122,6 @@ if sys.version_info >= (3, 10): return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ... @overload - def gather( - __coro_or_future1: _FutureT[Any], - __coro_or_future2: _FutureT[Any], - __coro_or_future3: _FutureT[Any], - __coro_or_future4: _FutureT[Any], - __coro_or_future5: _FutureT[Any], - __coro_or_future6: _FutureT[Any], - *coros_or_futures: _FutureT[Any], - return_exceptions: bool = ..., - ) -> Future[list[Any]]: ... - @overload def gather(__coro_or_future1: _FutureT[_T1], *, return_exceptions: bool) -> Future[tuple[_T1 | BaseException]]: ... @overload def gather( @@ -165,8 +156,21 @@ if sys.version_info >= (3, 10): ) -> Future[ tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException] ]: ... + @overload + def gather( + __coro_or_future1: _FutureT[Any], + __coro_or_future2: _FutureT[Any], + __coro_or_future3: _FutureT[Any], + __coro_or_future4: _FutureT[Any], + __coro_or_future5: _FutureT[Any], + __coro_or_future6: _FutureT[Any], + *coros_or_futures: _FutureT[Any], + return_exceptions: bool = ..., + ) -> Future[list[Any]]: ... else: + @overload + def gather(*, loop: AbstractEventLoop | None = ..., return_exceptions: bool = ...) -> Future[tuple[()]]: ... @overload def gather( __coro_or_future1: _FutureT[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ... @@ -210,18 +214,6 @@ else: return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ... @overload - def gather( - __coro_or_future1: _FutureT[Any], - __coro_or_future2: _FutureT[Any], - __coro_or_future3: _FutureT[Any], - __coro_or_future4: _FutureT[Any], - __coro_or_future5: _FutureT[Any], - __coro_or_future6: _FutureT[Any], - *coros_or_futures: _FutureT[Any], - loop: AbstractEventLoop | None = ..., - return_exceptions: bool = ..., - ) -> Future[list[Any]]: ... - @overload def gather( __coro_or_future1: _FutureT[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool ) -> Future[tuple[_T1 | BaseException]]: ... @@ -265,6 +257,18 @@ else: ) -> Future[ tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException] ]: ... + @overload + def gather( + __coro_or_future1: _FutureT[Any], + __coro_or_future2: _FutureT[Any], + __coro_or_future3: _FutureT[Any], + __coro_or_future4: _FutureT[Any], + __coro_or_future5: _FutureT[Any], + __coro_or_future6: _FutureT[Any], + *coros_or_futures: _FutureT[Any], + loop: AbstractEventLoop | None = ..., + return_exceptions: bool = ..., + ) -> Future[list[Any]]: ... def run_coroutine_threadsafe(coro: _FutureT[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...