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 |
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 |
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.