@@ -197,7 +197,7 @@ async def limited_as_completed(
197197 * ,
198198 limit : int = _DEFAULT_LIMITED_CONCURRENCY ,
199199 tasks_group_prefix : str | None = None ,
200- ) -> AsyncGenerator [asyncio .Future [T ], None ]:
200+ ) -> AsyncGenerator [asyncio .Task [T ], None ]:
201201 """Runs awaitables using limited concurrent tasks and returns
202202 result futures unordered.
203203
@@ -214,7 +214,7 @@ async def limited_as_completed(
214214 nothing
215215
216216 Yields:
217- Future [T]: the future of the awaitables as they appear.
217+ task [T]: the future of the awaitables as they appear.
218218
219219
220220 """
@@ -227,7 +227,7 @@ async def limited_as_completed(
227227 is_async = False
228228
229229 completed_all_awaitables = False
230- pending_futures : set [asyncio .Future ] = set ()
230+ pending_futures : set [asyncio .Task ] = set ()
231231
232232 try :
233233 while pending_futures or not completed_all_awaitables :
@@ -240,10 +240,11 @@ async def limited_as_completed(
240240 if is_async
241241 else next (awaitable_iterator ) # type: ignore[call-overload]
242242 )
243- future = asyncio .ensure_future (aw )
243+ future : asyncio . Task = asyncio .ensure_future (aw )
244244 if tasks_group_prefix :
245245 future .set_name (f"{ tasks_group_prefix } -{ future .get_name ()} " )
246246 pending_futures .add (future )
247+
247248 except (StopIteration , StopAsyncIteration ): # noqa: PERF203
248249 completed_all_awaitables = True
249250 if not pending_futures :
@@ -254,6 +255,7 @@ async def limited_as_completed(
254255
255256 for future in done :
256257 yield future
258+
257259 except asyncio .CancelledError :
258260 for future in pending_futures :
259261 future .cancel ()
0 commit comments