Skip to content

Commit 810dfa5

Browse files
[asyncio.tasks] Fix return type of as_completed (#15672)
When as_completed() is iterated with a regular for loop (not async for), it yields coroutines, not Futures. The previous stub incorrectly typed the sync iterator path as Iterator[Future[_T]] which would allow calling .result() without a type error even though that crashes at runtime with AttributeError.
1 parent ac78486 commit 810dfa5

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

stdlib/asyncio/tasks.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ ALL_COMPLETED: Final = concurrent.futures.ALL_COMPLETED
8787

8888
if sys.version_info >= (3, 13):
8989
@type_check_only
90-
class _SyncAndAsyncIterator(Iterator[_T_co], AsyncIterator[_T_co], Protocol[_T_co]): ...
90+
class _SyncAndAsyncIterator(Iterator[Coroutine[Any, Any, _T]], AsyncIterator[Future[_T]], Protocol[_T]): ...
9191

92-
def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = None) -> _SyncAndAsyncIterator[Future[_T]]: ...
92+
def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = None) -> _SyncAndAsyncIterator[_T]: ...
9393

9494
else:
9595
def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = None) -> Iterator[Future[_T]]: ...

0 commit comments

Comments
 (0)