INNER CODE UNIT · Python
from_context
volfpeter/htmy · htmy/core.py:135
def from_context(cls, context: Context, default: None) -> Self | None: ...
@overload
@classmethod
def from_context(cls, context: Context, default: Self) -> Self: ...
@classmethod
def from_context(cls, context: Context, default: Self | None = _MISSING) -> Self | None:
"""
Looks up an instance of this class from the given context.
Arguments:
context: The context the instance should be loaded from.
default: The default to use if no instance is found in the context. If omitted,
a `KeyError` is raised on absence.
Raises:
KeyError: If no instance was found and no `default` was given.