10000 Add 6th overload and union for return_exceptions=True · python/typeshed@3175987 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3175987

Browse files
authored
Add 6th overload and union for return_exceptions=True
1 parent 7a8a8f6 commit 3175987

File tree

1 file changed

+78
-47
lines changed

1 file changed

+78
-47
lines changed

stdlib/asyncio/tasks.pyi

Lines changed: 78 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ _T2 = TypeVar("_T2")
4242
_T3 = TypeVar("_T3")
4343
_T4 = TypeVar("_T4")
4444
_T5 = TypeVar("_T5")
45+
_T6 = TypeVar("_T6")
4546
_FT = TypeVar("_FT", bound=Future[Any])
4647
_FutureLike: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T]
4748
_TaskYieldType: TypeAlias = Future[object] | None
@@ -55,13 +56,13 @@ if sys.version_info >= (3, 10):
5556

5657
else:
5758
def as_completed(
58-
fs: Iterable[_FutureLike[_T]], *, loop: AbstractEventLoop | None = None, timeout: float | None = None
59+
fs: Iterable[_FutureLike[_T]], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ...
5960
) -> Iterator[Future[_T]]: ...
6061

6162
@overload
62-
def ensure_future(coro_or_future: _FT, *, loop: AbstractEventLoop | None = None) -> _FT: ... # type: ignore[misc]
63+
def ensure_future(coro_or_future: _FT, *, loop: AbstractEventLoop | None = ...) -> _FT: ... # type: ignore[misc]
6364
@overload
64-
def ensure_future(coro_or_future: Awaitable[_T], *, loop: AbstractEventLoop | None = None) -> Task[_T]: ...
65+
def ensure_future(coro_or_future: Awaitable[_T], *, loop: AbstractEventLoop | None = ...) -> Task[_T]: ...
6566

6667
# `gather()` actually returns a list with length equal to the number
6768
# of tasks passed; however, Tuple is used similar to the annotation for
@@ -72,18 +73,21 @@ def ensure_future(coro_or_future: Awaitable[_T], *, loop: AbstractEventLoop | No
7273
# but having overlapping overloads is the only way to get acceptable type inference in all edge cases.
7374
if sys.version_info >= (3, 10):
7475
@overload
75-
def gather(__coro_or_future1: _FutureLike[_T1], *, return_exceptions: Literal[False] = False) -> Future[tuple[_T1]]: ... # type: ignore[misc]
76+
def gather(__coro_or_future1: _FutureLike[_T1], *, return_exceptions: Literal[False] = ...) -> Future[tuple[_T1]]: ... # type: ignore[misc]
7677
@overload
7778
def gather( # type: ignore[misc]
78-
__coro_or_future1: _FutureLike[_T1], __coro_or_future2: _FutureLike[_T2], *, return_exceptions: Literal[False] = False
79+
__coro_or_future1: _FutureLike[_T1],
80+
__coro_or_future2: _FutureLike[_T2],
81+
*,
82+
return_exceptions: Literal[False] = ...,
7983
) -> Future[tuple[_T1, _T2]]: ...
8084
@overload
8185
def gather( # type: ignore[misc]
8286
__coro_or_future1: _FutureLike[_T1],
8387
__coro_or_future2: _FutureLike[_T2],
8488
__coro_or_future3: _FutureLike[_T3],
8589
*,
86-
return_exceptions: Literal[False] = False,
90+
return_exceptions: Literal[False] = ...,
8791
) -> Future[tuple[_T1, _T2, _T3]]: ...
8892
@overload
8993
def gather( # type: ignore[misc]
@@ -92,7 +96,7 @@ if sys.version_info >= (3, 10):
9296
__coro_or_future3: _FutureLike[_T3],
9397
__coro_or_future4: _FutureLike[_T4],
9498
*,
95-
return_exceptions: Literal[False] = False,
99+
return_exceptions: Literal[False] = ...,
96100
) -> Future[tuple[_T1, _T2, _T3, _T4]]: ...
97101
@overload
98102
def gather( # type: ignore[misc]
@@ -102,8 +106,19 @@ if sys.version_info >= (3, 10):
102106
__coro_or_future4: _FutureLike[_T4],
103107
__coro_or_future5: _FutureLike[_T5],
104108
*,
105-
return_exceptions: Literal[False] = False,
109+
return_exceptions: Literal[False] = ...,
106110
) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ...
111+
@overload
112+
def gather( # type: ignore[misc]
113+
__coro_or_future1: _FutureLike[_T1],
114+
__coro_or_future2: _FutureLike[_T2],
115+
__coro_or_future3: _FutureLike[_T3],
116+
__coro_or_future4: _FutureLike[_T4],
117+
__coro_or_future5: _FutureLike[_T5],
118+
__coro_or_future6: _FutureLike[_T6],
119+
*,
120+
return_exceptions: Literal[False] = ...,
121+
) -> Future[tuple[_T1, _T2, _T3, _T4, _T5, _T6]]: ...
107122
@overload
108123
def gather(*coros_or_futures: _FutureLike[_T], return_exceptions: Literal[False] = False) -> Future[list[_T]]: ... # type: ignore[misc]
109124
@overload
@@ -136,35 +151,39 @@ if sys.version_info >= (3, 10):
136151
__coro_or_future3: _FutureLike[_T3],
137152
__coro_or_future4: _FutureLike[_T4],
138153
__coro_or_future5: _FutureLike[_T5],
154+
__coro_or_future6: _FutureLike[_T6],
139155
*,
140156
return_exceptions: bool,
141157
) -> Future[
142-
tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException]
158+
tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException, _T6 | BaseException]
143159
]: ...
144160
@overload
145-
def gather(*coros_or_futures: _FutureLike[Any], return_exceptions: bool = False) -> Future[list[Any]]: ... # type: ignore[misc]
161+
def gather(*coros_or_futures: _FutureLike[_T], return_exceptions: bool = ...) -> Future[list[_T | BaseException]]: ... # type: ignore[misc]
146162

147163
else:
148164
@overload
149165
def gather( # type: ignore[misc]
150-
__coro_or_future1: _FutureLike[_T1], *, loop: AbstractEventLoop | None = None, return_exceptions: Literal[False] = False
166+
__coro_or_future1: _FutureLike[_T1],
167+
*,
168+
loop: AbstractEventLoop | None = ...,
169+
return_exceptions: Literal[False] = ...,
151170
) -> Future[tuple[_T1]]: ...
152171
@overload
153172
def gather( # type: ignore[misc]
154173
__coro_or_future1: _FutureLike[_T1],
155174
__coro_or_future2: _FutureLike[_T2],
156175
*,
157-
loop: AbstractEventLoop | None = None,
158-
return_exceptions: Literal[False] = False,
176+
loop: AbstractEventLoop | None = ...,
177+
return_exceptions: Literal[False] = ...,
159178
) -> Future[tuple[_T1, _T2]]: ...
160179
@overload
161180
def gather( # type: ignore[misc]
162181
__coro_or_future1: _FutureLike[_T1],
163182
__coro_or_future2: _FutureLike[_T2],
164183
__coro_or_future3: _FutureLike[_T3],
165184
*,
166-
loop: AbstractEventLoop | None = None,
167-
return_exceptions: Literal[False] = False,
185+
loop: AbstractEventLoop | None = ...,
186+
return_exceptions: Literal[False] = ...,
168187
) -> Future[tuple[_T1, _T2, _T3]]: ...
169188
@overload
170189
def gather( # type: ignore[misc]
@@ -173,8 +192,8 @@ else:
173192
__coro_or_future3: _FutureLike[_T3],
174193
__coro_or_future4: _FutureLike[_T4],
175194
*,
176-
loop: AbstractEventLoop | None = None,
177-
return_exceptions: Literal[False] = False,
195+
loop: AbstractEventLoop | None = ...,
196+
return_exceptions: Literal[False] = ...,
178197
) -> Future[tuple[_T1, _T2, _T3, _T4]]: ...
179198
@overload
180199
def gather( # type: ignore[misc]
@@ -184,23 +203,21 @@ else:
184203
__coro_or_future4: _FutureLike[_T4],
185204
__coro_or_future5: _FutureLike[_T5],
186205
*,
187-
loop: AbstractEventLoop | None = None,
188-
return_exceptions: Literal[False] = False,
206+
loop: AbstractEventLoop | None = ...,
207+
return_exceptions: Literal[False] = ...,
189208
) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ...
190209
@overload
191-
def gather( # type: ignore[misc]
192-
*coros_or_futures: _FutureLike[_T], loop: AbstractEventLoop | None = None, return_exceptions: Literal[False] = False
193-
) -> Future[list[_T]]: ...
210+
def gather(*coros_or_futures: _FutureLike[_T], return_exceptions: Literal[False] = False) -> Future[list[_T]]: ... # type: ignore[misc]
194211
@overload
195212
def gather( # type: ignore[misc]
196-
__coro_or_future1: _FutureLike[_T1], *, loop: AbstractEventLoop | None = None, return_exceptions: bool
213+
__coro_or_future1: _FutureLike[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool
197214
) -> Future[tuple[_T1 | BaseException]]: ...
198215
@overload
199216
def gather( # type: ignore[misc]
200217
__coro_or_future1: _FutureLike[_T1],
201218
__coro_or_future2: _FutureLike[_T2],
202219
*,
203-
loop: AbstractEventLoop | None = None,
220+
loop: AbstractEventLoop | None = ...,
204221
return_exceptions: bool,
205222
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException]]: ...
206223
@overload
@@ -209,7 +226,7 @@ else:
209226
__coro_or_future2: _FutureLike[_T2],
210227
__coro_or_future3: _FutureLike[_T3],
211228
*,
212-
loop: AbstractEventLoop | None = None,
229+
loop: AbstractEventLoop | None = ...,
213230
return_exceptions: bool,
214231
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException]]: ...
215232
@overload
@@ -219,7 +236,7 @@ else:
219236
__coro_or_future3: _FutureLike[_T3],
220237
__coro_or_future4: _FutureLike[_T4],
221238
*,
222-
loop: AbstractEventLoop | None = None,
239+
loop: AbstractEventLoop | None = ...,
223240
return_exceptions: bool,
224241
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException]]: ...
225242
@overload
@@ -230,15 +247,28 @@ else:
230247
__coro_or_future4: _FutureLike[_T4],
231248
__coro_or_future5: _FutureLike[_T5],
232249
*,
233-
loop: AbstractEventLoop | None = None,
250+
loop: AbstractEventLoop | None = ...,
234251
return_exceptions: bool,
235252
) -> Future[
236253
tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException]
254+
]: ...
255+
@overload
256+
def gather( # type: ignore[misc]
257+
__coro_or_future1: _FutureLike[_T1],
258+
__coro_or_future2: _FutureLike[_T2],
259+
__coro_or_future3: _FutureLike[_T3],
260+
__coro_or_future4: _FutureLike[_T4],
261+
__coro_or_future5: _FutureLike[_T5],
262+
__coro_or_future6: _FutureLike[_T6],
263+
*,
264+
return_exceptions: bool,
265+
) -> Future[
266+
tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException, _T6 | BaseException]
237267
]: ...
238268
@overload
239269
def gather( # type: ignore[misc]
240-
*coros_or_futures: _FutureLike[Any], loop: AbstractEventLoop | None = None, return_exceptions: bool = False
241-
) -> Future[list[Any]]: ...
270+
*coros_or_futures: _FutureLike[T], loop: AbstractEventLoop | None = ..., return_exceptions: bool = ...
271+
) -> Future[list[T | BaseException]]: ...
242272

243273
def run_coroutine_threadsafe(coro: _FutureLike[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...
244274

@@ -249,36 +279,32 @@ if sys.version_info >= (3, 10):
249279
@overload
250280
async def sleep(delay: float, result: _T) -> _T: ...
251281
@overload
252-
async def wait(fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED") -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
282+
async def wait(fs: Iterable[_FT], *, timeout: float | None = ..., return_when: str = ...) -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
253283
@overload
254284
async def wait(
255-
fs: Iterable[Awaitable[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
285+
fs: Iterable[Awaitable[_T]], *, timeout: float | None = ..., return_when: str = ...
256286
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
257287
async def wait_for(fut: _FutureLike[_T], timeout: float | None) -> _T: ...
258288

259289
else:
260-
def shield(arg: _FutureLike[_T], *, loop: AbstractEventLoop | None = None) -> Future[_T]: ...
290+
def shield(arg: _FutureLike[_T], *, loop: AbstractEventLoop | None = ...) -> Future[_T]: ...
261291
@overload
262-
async def sleep(delay: float, *, loop: AbstractEventLoop | None = None) -> None: ...
292+
async def sleep(delay: float, *, loop: AbstractEventLoop | None = ...) -> None: ...
263293
@overload
264-
async def sleep(delay: float, result: _T, *, loop: AbstractEventLoop | None = None) -> _T: ...
294+
async def sleep(delay: float, result: _T, *, loop: AbstractEventLoop | None = ...) -> _T: ...
265295
@overload
266296
async def wait( # type: ignore[misc]
267-
fs: Iterable[_FT],
268-
*,
269-
loop: AbstractEventLoop | None = None,
270-
timeout: float | None = None,
271-
return_when: str = "ALL_COMPLETED",
297+
fs: Iterable[_FT], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ..., return_when: str = ...
272298
) -> tuple[set[_FT], set[_FT]]: ...
273299
@overload
274300
async def wait(
275301
fs: Iterable[Awaitable[_T]],
276302
*,
277-
loop: AbstractEventLoop | None = None,
278-
timeout: float | None = None,
279-
return_when: str = "ALL_COMPLETED",
303+
loop: AbstractEventLoop | None = ...,
304+
timeout: float | None = ...,
305+
return_when: str = ...,
280306
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
281-
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = None) -> _T: ...
307+
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = ...) -> _T: ...
282308

283309
# mypy and pyright complain that a subclass of an invariant class shouldn't be covariant.
284310
# While this is true in general, here it's sort-of okay to have a covariant subclass,
@@ -309,21 +335,26 @@ class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright:
309335
def uncancel(self) -> int: ...
310336
if sys.version_info < (3, 9):
311337
@classmethod
312-
def current_task(cls, loop: AbstractEventLoop | None = None) -> Task[Any] | None: ...
338+
def current_task(cls, loop: AbstractEventLoop | None = ...) -> Task[Any] | None: ...
313339
@classmethod
314-
def all_tasks(cls, loop: AbstractEventLoop | None = None) -> set[Task[Any]]: ...
340+
def all_tasks(cls, loop: AbstractEventLoop | None = ...) -> set[Task[Any]]: ...
315341
if sys.version_info >= (3, 9):
316342
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
317343

318344
def all_tasks(loop: AbstractEventLoop | None = None) -> set[Task[Any]]: ...
319345

320346
if sys.version_info >= (3, 11):
321347
def create_task(
322-
coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = None, context: Context | None = None
348+
coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T],
349+
*,
350+
name: str | None = None,
351+
context: Context | None = None,
323352
) -> Task[_T]: ...
324353

325354
elif sys.version_info >= (3, 8):
326-
def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = None) -> Task[_T]: ...
355+
def create_task(
356+
coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = ...
357+
) -> Task[_T]: ...
327358

328359
else:
329360
def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T]) -> Task[_T]: ...

0 commit comments

Comments
 (0)
0