Skip to content

Commit ff852aa

Browse files
bpo-42230: Improve asyncio documentation regarding accepting sets vs iterables (GH-23073)
People call wait() and as_completed() with various non-set iterables, a list should be the most common but there are others as well[1]. Considering typeshed also documents wait()[2] and as_completed()[3] as accepting arbitrary iterables I think it's a good idea to document the status quo better. [1] aio-libs/aiokafka#672 [2] https://github.com/python/typeshed/blob/620989bac572f30349b95590ebe81a73ce0fe862/stdlib/3/asyncio/tasks.pyiGH-L161 [3] https://github.com/python/typeshed/blob/620989bac572f30349b95590ebe81a73ce0fe862/stdlib/3/asyncio/tasks.pyiGH-L40 (cherry picked from commit 3d86d09) Co-authored-by: Jakub Stasiak <[email protected]>
1 parent 27c72ba commit ff852aa

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Doc/library/asyncio-task.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,10 @@ Waiting Primitives
504504
return_when=ALL_COMPLETED)
505505

506506
Run :ref:`awaitable objects <asyncio-awaitables>` in the *aws*
507-
set concurrently and block until the condition specified
507+
iterable concurrently and block until the condition specified
508508
by *return_when*.
509509

510-
The *aws* set must not be empty.
510+
The *aws* iterable must not be empty.
511511

512512
Returns two sets of Tasks/Futures: ``(done, pending)``.
513513

@@ -593,9 +593,9 @@ Waiting Primitives
593593
.. function:: as_completed(aws, \*, loop=None, timeout=None)
594594

595595
Run :ref:`awaitable objects <asyncio-awaitables>` in the *aws*
596-
set concurrently. Return an iterator of coroutines.
596+
iterable concurrently. Return an iterator of coroutines.
597597
Each coroutine returned can be awaited to get the earliest next
598-
result from the set of the remaining awaitables.
598+
result from the iterable of the remaining awaitables.
599599

600600
Raises :exc:`asyncio.TimeoutError` if the timeout occurs before
601601
all Futures are done.

Lib/asyncio/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def create_task(coro, *, name=None):
373373
async def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED):
374374
"""Wait for the Futures and coroutines given by fs to complete.
375375
376-
The sequence futures must not be empty.
376+
The fs iterable must not be empty.
377377
378378
Coroutines will be wrapped in Tasks.
379379
@@ -573,7 +573,7 @@ def as_completed(fs, *, loop=None, timeout=None):
573573
Note: The futures 'f' are not necessarily members of fs.
574574
"""
575575
if futures.isfuture(fs) or coroutines.iscoroutine(fs):
576-
raise TypeError(f"expect a list of futures, not {type(fs).__name__}")
576+
raise TypeError(f"expect an iterable of futures, not {type(fs).__name__}")
577577

578578
from .queues import Queue # Import here to avoid circular import problem.
579579
done = Queue(loop=loop)

0 commit comments

Comments
 (0)