mirror of
https://github.com/python/cpython.git
synced 2026-02-06 09:50:43 +00:00
[3.14] gh-142119: Clarify that one contextvars.Token can only reset once in a lifetime (GH-143693) (GH-144266)
(cherry picked from commit 487bd2dea5)
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
This commit is contained in:
parent
d11c067246
commit
b82b12bc80
1 changed files with 3 additions and 1 deletions
|
|
@ -119,13 +119,15 @@ Context Variables
|
|||
# After the reset call the var has no value again, so
|
||||
# var.get() would raise a LookupError.
|
||||
|
||||
The same *token* cannot be used twice.
|
||||
|
||||
|
||||
.. class:: Token
|
||||
|
||||
*Token* objects are returned by the :meth:`ContextVar.set` method.
|
||||
They can be passed to the :meth:`ContextVar.reset` method to revert
|
||||
the value of the variable to what it was before the corresponding
|
||||
*set*.
|
||||
*set*. A single token cannot reset a context variable more than once.
|
||||
|
||||
Tokens support the :ref:`context manager protocol <context-managers>`
|
||||
to automatically reset context variables. See :meth:`ContextVar.set`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue