Skip to content

Commit 00bf086

Browse files
authored
[3.13] gh-155894: Fix wait_for() docs claiming a coroutine is wrapped in a Task (#156045)
1 parent 49fe8bd commit 00bf086

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

Doc/library/asyncio-task.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -840,17 +840,13 @@ Timeouts
840840
Wait for the *aw* :ref:`awaitable <asyncio-awaitables>`
841841
to complete with a timeout.
842842

843-
If *aw* is a coroutine it is automatically scheduled as a Task.
844-
845843
*timeout* can either be ``None`` or a float or int number of seconds
846844
to wait for. If *timeout* is ``None``, block until the future
847845
completes.
848846

849-
If a timeout occurs, it cancels the task and raises
850-
:exc:`TimeoutError`.
847+
If a timeout occurs, it cancels *aw* and raises :exc:`TimeoutError`.
851848

852-
To avoid the task :meth:`cancellation <Task.cancel>`,
853-
wrap it in :func:`shield`.
849+
To prevent *aw* from being cancelled, wrap it in :func:`shield`.
854850

855851
The function will wait until the future is actually cancelled,
856852
so the total wait time may exceed the *timeout*. If an exception
@@ -891,6 +887,10 @@ Timeouts
891887
.. versionchanged:: 3.11
892888
Raises :exc:`TimeoutError` instead of :exc:`asyncio.TimeoutError`.
893889

890+
.. versionchanged:: 3.12
891+
Implemented using :func:`asyncio.timeout`, a coroutine passed as *aw*
892+
is no longer wrapped in a :class:`Task` when *timeout* is positive.
893+
894894

895895
Waiting primitives
896896
==================

Lib/asyncio/tasks.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,13 @@ def _release_waiter(waiter, *args):
459459
async def wait_for(fut, timeout):
460460
"""Wait for the single Future or coroutine to complete, with timeout.
461461
462-
Coroutine will be wrapped in Task.
463-
464462
Returns result of the Future or coroutine. When a timeout occurs,
465-
it cancels the task and raises TimeoutError. To avoid the task
466-
cancellation, wrap it in shield().
463+
it cancels fut and raises TimeoutError. To prevent fut from being
464+
cancelled, wrap it in shield().
467465
468-
If the wait is cancelled, the task is also cancelled.
466+
If the wait is cancelled, fut is also cancelled.
469467
470-
If the task suppresses the cancellation and returns a value instead,
468+
If fut suppresses the cancellation and returns a value instead,
471469
that value is returned.
472470
473471
This function is a coroutine.

0 commit comments

Comments
 (0)