Skip to content

Commit 4ee2068

Browse files
authored
gh-104254: Document the optional keyword-only "context" argument to Task constructor (#104251)
(This was added in 3.11. It was already documented for `create_task()`, but not for `Task()`.)
1 parent 42f54d1 commit 4ee2068

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Doc/library/asyncio-task.rst

+8-4
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ Introspection
10141014
Task Object
10151015
===========
10161016

1017-
.. class:: Task(coro, *, loop=None, name=None)
1017+
.. class:: Task(coro, *, loop=None, name=None, context=None)
10181018

10191019
A :class:`Future-like <Future>` object that runs a Python
10201020
:ref:`coroutine <coroutine>`. Not thread-safe.
@@ -1049,9 +1049,10 @@ Task Object
10491049
APIs except :meth:`Future.set_result` and
10501050
:meth:`Future.set_exception`.
10511051

1052-
Tasks support the :mod:`contextvars` module. When a Task
1053-
is created it copies the current context and later runs its
1054-
coroutine in the copied context.
1052+
An optional keyword-only *context* argument allows specifying a
1053+
custom :class:`contextvars.Context` for the *coro* to run in.
1054+
If no *context* is provided, the Task copies the current context
1055+
and later runs its coroutine in the copied context.
10551056

10561057
.. versionchanged:: 3.7
10571058
Added support for the :mod:`contextvars` module.
@@ -1063,6 +1064,9 @@ Task Object
10631064
Deprecation warning is emitted if *loop* is not specified
10641065
and there is no running event loop.
10651066

1067+
.. versionchanged:: 3.11
1068+
Added the *context* parameter.
1069+
10661070
.. method:: done()
10671071

10681072
Return ``True`` if the Task is *done*.

0 commit comments

Comments
 (0)