https://github.com/python/cpython/commit/b82b12bc80373e2cfd0c0bed273e55e67640cdfd commit: b82b12bc80373e2cfd0c0bed273e55e67640cdfd branch: 3.14 author: Miss Islington (bot) <[email protected]> committer: encukou <[email protected]> date: 2026-01-27T11:39:13+01:00 summary:
[3.14] gh-142119: Clarify that one `contextvars.Token` can only reset once in a lifetime (GH-143693) (GH-144266) (cherry picked from commit 487bd2dea538e36cb620dd9e0f298d731b9ede8a) Co-authored-by: Bartosz Sławecki <[email protected]> files: M Doc/library/contextvars.rst diff --git a/Doc/library/contextvars.rst b/Doc/library/contextvars.rst index 043a8d9d9205bd..21426225df10fb 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]
