[Python-checkins] [3.11] gh-104254: Document the optional keyword-only "context" argument to Task constructor (GH-104251) (#104258)

kumaraditya303 webhook-mailer at python.org
Sun May 7 00:22:30 EDT 2023


https://github.com/python/cpython/commit/efcd4bcb87a8a461ccf8f6038f75e638d86eeb8c
commit: efcd4bcb87a8a461ccf8f6038f75e638d86eeb8c
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: kumaraditya303 <59607654+kumaraditya303 at users.noreply.github.com>
date: 2023-05-07T09:52:23+05:30
summary:

[3.11] gh-104254: Document the optional keyword-only "context" argument to Task constructor (GH-104251) (#104258)

gh-104254: Document the optional keyword-only "context" argument to Task constructor (GH-104251)

(This was added in 3.11. It was already documented for `create_task()`, but not for `Task()`.)
(cherry picked from commit 4ee2068c34bd45eddba7f6a8ee83f62d5b6932fc)

Co-authored-by: Itamar Ostricher <itamarost at gmail.com>

files:
M Doc/library/asyncio-task.rst

diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst
index bfefe8e3815b..550a84ebae39 100644
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -967,7 +967,7 @@ Introspection
 Task Object
 ===========
 
-.. class:: Task(coro, *, loop=None, name=None)
+.. class:: Task(coro, *, loop=None, name=None, context=None)
 
    A :class:`Future-like <Future>` object that runs a Python
    :ref:`coroutine <coroutine>`.  Not thread-safe.
@@ -1002,9 +1002,10 @@ Task Object
    APIs except :meth:`Future.set_result` and
    :meth:`Future.set_exception`.
 
-   Tasks support the :mod:`contextvars` module.  When a Task
-   is created it copies the current context and later runs its
-   coroutine in the copied context.
+   An optional keyword-only *context* argument allows specifying a
+   custom :class:`contextvars.Context` for the *coro* to run in.
+   If no *context* is provided, the Task copies the current context
+   and later runs its coroutine in the copied context.
 
    .. versionchanged:: 3.7
       Added support for the :mod:`contextvars` module.
@@ -1016,6 +1017,9 @@ Task Object
       Deprecation warning is emitted if *loop* is not specified
       and there is no running event loop.
 
+   .. versionchanged:: 3.11
+      Added the *context* parameter.
+
    .. method:: done()
 
       Return ``True`` if the Task is *done*.



More information about the Python-checkins mailing list