Documentation Index
Fetch the complete documentation index at: https://mintlify.com/alex-ber/AlexBerUtils/llms.txt
Use this file to discover all available pages before exploring further.
contextvars.ContextVar provides per-context (per-async-task or per-thread) state. AlexBerUtils provides two helpers for discovering all ContextVar instances in a module and resetting them to a known initial state.
get_context_vars
Scans one or more modules for top-level ContextVar instances, pairs each one with a factory function that produces its default value, resets them all immediately, and returns the list of entity dicts.
Parameters
One or more Python module objects to scan.
dir(module) is used to enumerate attributes; only those that are ContextVar instances are collected.Optional function that resolves the factory callable for a given
ContextVar.Signature: (var: ContextVar, module: ModuleType) -> CallableDefault: looks for an attribute named <var.name>_DEFAULT on the same module as the ContextVar.Return value
Alist of dicts, each with:
| Key | Type | Description |
|---|---|---|
"var" | ContextVar | The ContextVar instance. |
"factory" | Callable | Zero-argument callable that produces the default value. |
get_context_vars calls reset_context_vars internally, so all discovered vars are reset to their defaults before the list is returned.
If no modules are passed, an empty list is returned immediately.
Usage
reset_context_vars
Resets every ContextVar in the entity list to its default value by calling its associated factory.
Entity dicts as produced by
get_context_vars. Each dict must have a "var" (ContextVar) and a "factory" (callable).ValueError if any factory is not callable.
