From 0e18375907f8fbd92d621f096f15fd64a1fc8da0 Mon Sep 17 00:00:00 2001 From: johnslavik Date: Sun, 11 Jan 2026 16:00:40 +0100 Subject: [PATCH 1/3] Clarify that `contextvar.Token` objects are for single use --- Doc/library/contextvars.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/contextvars.rst b/Doc/library/contextvars.rst index b218468a084db1..2ce66d0aa7743b 100644 --- a/Doc/library/contextvars.rst +++ b/Doc/library/contextvars.rst @@ -93,13 +93,14 @@ 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. The token supports :ref:`context manager protocol ` to restore the corresponding context variable value at the exit from From c29b7ec72f7d120809dca7289739b47942ead596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20S=C5=82awecki?= Date: Sun, 11 Jan 2026 18:49:29 +0100 Subject: [PATCH 2/3] Preserve spacing between sections Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/library/contextvars.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/library/contextvars.rst b/Doc/library/contextvars.rst index 2ce66d0aa7743b..831e9407d36442 100644 --- a/Doc/library/contextvars.rst +++ b/Doc/library/contextvars.rst @@ -95,6 +95,7 @@ Context Variables The same *token* cannot be used twice. + .. class:: Token *Token* objects are returned by the :meth:`ContextVar.set` method. From ae102903015c32c31b4084d6911a2b3037c7c516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20S=C5=82awecki?= Date: Sat, 17 Jan 2026 09:40:26 +0100 Subject: [PATCH 3/3] Make wording nicer --- Doc/library/contextvars.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/contextvars.rst b/Doc/library/contextvars.rst index 831e9407d36442..b4009ac2065798 100644 --- a/Doc/library/contextvars.rst +++ b/Doc/library/contextvars.rst @@ -103,7 +103,7 @@ Context Variables the value of the variable to what it was before the corresponding *set*. A single token cannot reset a context variable more than once. - The token supports :ref:`context manager protocol ` + Tokens support :ref:`context manager protocol ` to restore the corresponding context variable value at the exit from :keyword:`with` block::