ContextStack

class app.util.config.context_stack.ContextStack[source]

Bases: object

ContextStack(name: str | None = None, parent: ‘ContextStack | None’ = None, current: CurrentType | None = None, token: _contextvars.Token | None = None)

Inheritance diagram of ContextStack

Inheritance Diagram for ContextStack

Methods

__init__([name, parent, current, token])

find_inheritance(name[, skip])

Find a context by name in the stack.

find_name(name[, skip])

Check if a context with the given name exists in the stack.

get()

Get the current context from the stack.

iterate([skip])

Iterate over the current context and all parent contexts.

pop([token])

Pop the current context from the stack and return it.

push(current[, name])

Push a new context onto the stack.

with_context(cls, current[, name])

Context manager to push a new context onto the stack.

with_updated_name(cls, name)

Attributes

CurrentType

current

name

parent

token

CurrentType = CurrentType
__init__(name=None, parent=None, current=None, token=None)
Parameters:
Return type:

None

current: TypeAliasType | None = None
classmethod find_inheritance(name, skip=0)[source]

Find a context by name in the stack.

Return type:

dict[str, Any] | BaseModel | None

Parameters:
classmethod find_name(name, skip=0)[source]

Check if a context with the given name exists in the stack.

Return type:

bool

Parameters:
classmethod get()[source]

Get the current context from the stack. If the stack is empty, return None.

Return type:

ContextStack | None

classmethod iterate(skip=0)[source]

Iterate over the current context and all parent contexts.

Return type:

Generator[ContextStack, None, None]

Parameters:

skip (int)

name: str | None = None
parent: ContextStack | None = None
classmethod pop(token=None)[source]

Pop the current context from the stack and return it. If the stack is empty, return None.

Return type:

None

Parameters:

token (Token | None)

classmethod push(current, name=None)[source]

Push a new context onto the stack.

Return type:

ContextStack

Parameters:
  • current (CurrentType)

  • name (str | None)

token: Token | None = None
classmethod with_context(cls, current, name=None)[source]

Context manager to push a new context onto the stack.

Return type:

Any

Parameters:
  • current (CurrentType)

  • name (str | None)

classmethod with_updated_name(cls, name)[source]
Return type:

Any

Parameters:

name (str)