Skip to content

Commit efcd4bc

Browse files
[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 4ee2068) Co-authored-by: Itamar Ostricher <[email protected]>
1 parent 8f23cad commit efcd4bc

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
@@ -967,7 +967,7 @@ Introspection
967967
Task Object
968968
===========
969969

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

972972
A :class:`Future-like <Future>` object that runs a Python
973973
:ref:`coroutine <coroutine>`. Not thread-safe.
@@ -1002,9 +1002,10 @@ Task Object
10021002
APIs except :meth:`Future.set_result` and
10031003
:meth:`Future.set_exception`.
10041004

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

10091010
.. versionchanged:: 3.7
10101011
Added support for the :mod:`contextvars` module.
@@ -1016,6 +1017,9 @@ Task Object
10161017
Deprecation warning is emitted if *loop* is not specified
10171018
and there is no running event loop.
10181019

1020+
.. versionchanged:: 3.11
1021+
Added the *context* parameter.
1022+
10191023
.. method:: done()
10201024

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

0 commit comments

Comments
 (0)