From 487bd2dea538e36cb620dd9e0f298d731b9ede8a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20S=C5=82awecki?= Date: Tue, 27 Jan 2026 10:49:05 +0100 Subject: [PATCH] gh-142119: Clarify that one `contextvars.Token` can only reset once in a lifetime (GH-143693) --- Doc/library/contextvars.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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`. -- 2.47.3