https://github.com/python/cpython/commit/05ab13e1019a8d734ceceb28dffc83619bf8880c
commit: 05ab13e1019a8d734ceceb28dffc83619bf8880c
branch: main
author: Timofei Ivankov <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-08-18T18:52:43+05:30
summary:
gh-155894: Fix asyncio.wait_for() docs claiming a coroutine is wrapped in a
Task (#155895)
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 596cb7565a66e7d..c6f0fb8a50917ac 100644
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -843,17 +843,13 @@ Timeouts
Wait for the *fut* :ref:`awaitable <asyncio-awaitables>`
to complete with a timeout.
- If *fut* 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 *fut* and raises :exc:`TimeoutError`.
- To avoid the task :meth:`cancellation <Task.cancel>`,
- wrap it in :func:`shield`.
+ To prevent *fut* 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
@@ -894,6 +890,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 *fut*
+ 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 7889d4793a5dec3..498eec3f31b292b 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -440,15 +440,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]