From: Bartosz Sławecki Date: Tue, 27 Jan 2026 09:49:05 +0000 (+0100) Subject: gh-142119: Clarify that one `contextvars.Token` can only reset once in a lifetime... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=487bd2dea538e36cb620dd9e0f298d731b9ede8a;p=thirdparty%2FPython%2Fcpython.git gh-142119: Clarify that one `contextvars.Token` can only reset once in a lifetime (GH-143693) --- diff --git a/Doc/library/contextvars.rst b/Doc/library/contextvars.rst index 60376e730cb1..653d8b597c23 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 ` to automatically reset context variables. See :meth:`ContextVar.set`.