Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Feb 9, 2025
1 parent 0400e8e commit 61abb23
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Doc/library/contextvars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ Context Variables
the value of the variable to what it was before the corresponding
*set*.

The token supports :ref:`context manager protocol <context-managers>`
to restore the corresponding context variable value at the exit from
:keyword:`with` block::

var = ContextVar('var', default='default value')

with var.set('new value'):
assert var.get() == 'new value'

assert var.get() == 'default value'

.. versionadded:: next

Added support for usage as a context manager.

.. attribute:: Token.var

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

0 comments on commit 61abb23

Please sign in to comment.