💾 Archived View for tris.fyi › pydoc › _contextvars captured on 2022-06-11 at 21:33:52. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-01-08)

➡️ Next capture (2023-01-29)

-=-=-=-=-=-=-

Back to module index

Go to module by name

_contextvars

Context Variables

Classes

Context

copy(self, /)

  Return a shallow copy of the context object.
get(self, key, default=None, /)

  Return the value for `key` if `key` has the value in the context object.

  If `key` does not exist, return `default`. If `default` is not given,
  return None.
items(self, /)

  Return all variables and their values in the context object.

  The result is returned as a list of 2-tuples (variable, value).
keys(self, /)

  Return a list of all variables in the context object.
run(...)
values(self, /)

  Return a list of all variables' values in the context object.

ContextVar

get(...)

  Return a value for the context variable for the current context.

  If there is no value for the variable in the current context, the method will:
   * return the value of the default argument of the method, if provided; or
   * return the default value for the context variable, if it was created
     with one; or
   * raise a LookupError.
reset(self, token, /)

  Reset the context variable.

  The variable is reset to the value it had before the `ContextVar.set()` that
  created the token was used.
set(self, value, /)

  Call to set a new value for the context variable in the current context.

  The required value argument is the new value for the context variable.

  Returns a Token object that can be used to restore the variable to its previous
  value via the `ContextVar.reset()` method.
name = <member 'name' of 'ContextVar' objects>

Token

MISSING = <Token.MISSING>
old_value = <attribute 'old_value' of 'Token' objects>
var = <attribute 'var' of 'Token' objects>

Functions

copy_context

copy_context()