class documentation

class LocalStack(t.Generic[T]): (source)

View In Hierarchy

Create a stack of context-local data. This wraps a :class:`ContextVar` containing a :class:`list` value. This may incur a performance penalty compared to using individual context vars, as it has to copy data to avoid mutating the list between nested contexts. :param context_var: The :class:`~contextvars.ContextVar` to use as storage for this local. If not given, one will be created. Context vars not created at the global scope may interfere with garbage collection. .. versionchanged:: 2.0 Uses ``ContextVar`` instead of a custom storage implementation. .. versionadded:: 0.6.1

Method __call__ Create a :class:`LocalProxy` that accesses the top of this local stack.
Method __init__ Undocumented
Method __release_local__ Undocumented
Method pop Remove the top item from the stack and return it. If the stack is empty, return ``None``.
Method push Add a new item to the top of the stack.
Class Variable __slots__ Undocumented
Property top The topmost item on the stack. If the stack is empty, `None` is returned.
Instance Variable _storage Undocumented
def __call__(self, name: t.Optional[str] = None, *, unbound_message: t.Optional[str] = None) -> LocalProxy: (source)

Create a :class:`LocalProxy` that accesses the top of this local stack. :param name: If given, the proxy access this attribute of the top item, rather than the item itself. :param unbound_message: The error message that the proxy will show if the stack is empty.

def __init__(self, context_var: t.Optional[ContextVar[t.List[T]]] = None): (source)

Undocumented

def __release_local__(self): (source)

Undocumented

def pop(self) -> t.Optional[T]: (source)

Remove the top item from the stack and return it. If the stack is empty, return ``None``.

def push(self, obj: T) -> t.List[T]: (source)

Add a new item to the top of the stack.

__slots__: tuple[str, ...] = (source)

Undocumented

The topmost item on the stack. If the stack is empty, `None` is returned.

_storage = (source)

Undocumented