]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-142119: Clarify that one `contextvars.Token` can only reset once in a lifetime...
authorBartosz Sławecki <bartosz@ilikepython.com>
Tue, 27 Jan 2026 09:49:05 +0000 (10:49 +0100)
committerGitHub <noreply@github.com>
Tue, 27 Jan 2026 09:49:05 +0000 (10:49 +0100)
Doc/library/contextvars.rst

index 60376e730cb1027ddb5d345a2c9a7c0fb094abe3..653d8b597c23628c12b6e8199ae50084578939e4 100644 (file)
@@ -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`.