Skip to content

Commit ad37c66

Browse files
authored
[3.8] bpo-42230: Improve asyncio documentation regarding accepting sets vs iterables (GH-23073) (GH-23105)
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 1341582 commit ad37c66

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Doc/library/asyncio-task.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ Waiting Primitives
501501
return_when=ALL_COMPLETED)
502502

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

507507
Returns two sets of Tasks/Futures: ``(done, pending)``.
@@ -588,9 +588,9 @@ Waiting Primitives
588588
.. function:: as_completed(aws, \*, loop=None, timeout=None)
589589

590590
Run :ref:`awaitable objects <asyncio-awaitables>` in the *aws*
591-
set concurrently. Return an iterator of coroutines.
591+
iterable concurrently. Return an iterator of coroutines.
592592
Each coroutine returned can be awaited to get the earliest next
593-
result from the set of the remaining awaitables.
593+
result from the iterable of the remaining awaitables.
594594

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

Lib/asyncio/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def create_task(coro, *, name=None):
394394
async def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED):
395395
"""Wait for the Futures and coroutines given by fs to complete.
396396
397-
The sequence futures must not be empty.
397+
The fs iterable must not be empty.
398398
399399
Coroutines will be wrapped in Tasks.
400400
@@ -580,7 +580,7 @@ def as_completed(fs, *, loop=None, timeout=None):
580580
Note: The futures 'f' are not necessarily members of fs.
581581
"""
582582
if futures.isfuture(fs) or coroutines.iscoroutine(fs):
583-
raise TypeError(f"expect a list of futures, not {type(fs).__name__}")
583+
raise TypeError(f"expect an iterable of futures, not {type(fs).__name__}")
584584

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

0 commit comments

Comments
 (0)