https://github.com/python/cpython/commit/487bd2dea538e36cb620dd9e0f298d731b9ede8a
commit: 487bd2dea538e36cb620dd9e0f298d731b9ede8a
branch: main
author: Bartosz Sławecki <[email protected]>
committer: encukou <[email protected]>
date: 2026-01-27T10:49:05+01:00
summary:
gh-142119: Clarify that one `contextvars.Token` can only reset once in a
lifetime (GH-143693)
files:
M Doc/library/contextvars.rst
diff --git a/Doc/library/contextvars.rst b/Doc/library/contextvars.rst
index 60376e730cb102..653d8b597c2362 100644
--- a/Doc/library/contextvars.rst
+++ b/Doc/library/contextvars.rst
@@ -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`.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]