https://github.com/python/cpython/commit/00bf086a68eabb2a26c99f4f5a34f15560221cce
commit: 00bf086a68eabb2a26c99f4f5a34f15560221cce
branch: 3.13
author: Timofei Ivankov <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-08-19T12:48:33Z
summary:
[3.13] gh-155894: Fix wait_for() docs claiming a coroutine is wrapped in a Task
(#156045)
files:
M Doc/library/asyncio-task.rst
M Lib/asyncio/tasks.py
diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst
index cd719b302a74ec6..afa7ea10e6f9bd4 100644
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -840,17 +840,13 @@ Timeouts
Wait for the *aw* :ref:`awaitable <asyncio-awaitables>`
to complete with a timeout.
- If *aw* is a coroutine it is automatically scheduled as a Task.
-
*timeout* can either be ``None`` or a float or int number of seconds
to wait for. If *timeout* is ``None``, block until the future
completes.
- If a timeout occurs, it cancels the task and raises
- :exc:`TimeoutError`.
+ If a timeout occurs, it cancels *aw* and raises :exc:`TimeoutError`.
- To avoid the task :meth:`cancellation <Task.cancel>`,
- wrap it in :func:`shield`.
+ To prevent *aw* from being cancelled, wrap it in :func:`shield`.
The function will wait until the future is actually cancelled,
so the total wait time may exceed the *timeout*. If an exception
@@ -891,6 +887,10 @@ Timeouts
.. versionchanged:: 3.11
Raises :exc:`TimeoutError` instead of :exc:`asyncio.TimeoutError`.
+ .. versionchanged:: 3.12
+ Implemented using :func:`asyncio.timeout`, a coroutine passed as *aw*
+ is no longer wrapped in a :class:`Task` when *timeout* is positive.
+
Waiting primitives
==================
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index e5e7d3e4aa9b5ea..19eab6d451bcbb4 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -459,15 +459,13 @@ def _release_waiter(waiter, *args):
async def wait_for(fut, timeout):
"""Wait for the single Future or coroutine to complete, with timeout.
- Coroutine will be wrapped in Task.
-
Returns result of the Future or coroutine. When a timeout occurs,
- it cancels the task and raises TimeoutError. To avoid the task
- cancellation, wrap it in shield().
+ it cancels fut and raises TimeoutError. To prevent fut from being
+ cancelled, wrap it in shield().
- If the wait is cancelled, the task is also cancelled.
+ If the wait is cancelled, fut is also cancelled.
- If the task suppresses the cancellation and returns a value instead,
+ If fut suppresses the cancellation and returns a value instead,
that value is returned.
This function is a coroutine.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]