Skip to content

Commit 61abb23

Browse files
committed
Update docs
1 parent 0400e8e commit 61abb23

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Doc/library/contextvars.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ Context Variables
101101
the value of the variable to what it was before the corresponding
102102
*set*.
103103

104+
The token supports :ref:`context manager protocol <context-managers>`
105+
to restore the corresponding context variable value at the exit from
106+
:keyword:`with` block::
107+
108+
var = ContextVar('var', default='default value')
109+
110+
with var.set('new value'):
111+
assert var.get() == 'new value'
112+
113+
assert var.get() == 'default value'
114+
115+
.. versionadded:: next
116+
117+
Added support for usage as a context manager.
118+
104119
.. attribute:: Token.var
105120

106121
A read-only property. Points to the :class:`ContextVar` object

0 commit comments

Comments
 (0)