yera.apps.context

Per-invocation app context, accessible via a ContextVar.

The @app decorator pushes an AppContext onto a stack on entry and pops it on exit; user code reads the current context via get_app_context.

Symbols

class AppContext — Per-invocation runtime context for an executing app.
def get_app_context — Return the currently executing app's runtime context.
def no_active_app_context — Return ``True`` if no app context is currently active.

AppContext

Per-invocation runtime context for an executing app.

Pushed onto a ContextVar stack on entry and popped on exit. Tracks the app's metadata, an instance counter, and its position in the app stack (top-level vs. nested). Managed by the @app decorator; not constructed by user code.

Attributes

metadata

AppMetadata describing the app this context belongs to.

instance_number

Counter for this app's invocations within a single run.

Methods

__enter__ — Push this context onto the stack and return it.
__exit__ — Pop this context off the stack.
top_level — Return whether this context is the outermost app on the stack.

AppContext.__enter__

__enter__()

Push this context onto the stack and return it.

AppContext.__exit__

__exit__(
    exc_type: type[BaseException] | None,
    exc_val: BaseException | None,
    exc_tb: TracebackType | None,
)

Pop this context off the stack.

AppContext.top_level

top_level() → bool

Return whether this context is the outermost app on the stack.

Raises

RuntimeError

If called before the context has been entered.

get_app_context

get_app_context() → AppContext

Return the currently executing app's runtime context.

For framework code that needs to inspect the running app (e.g. its metadata or position in the app stack). User code in an app's body rarely needs this.

Returns

type: AppContext

The active AppContext.

Raises

RuntimeError

If called outside an active app invocation.

no_active_app_context

no_active_app_context() → bool

Return True if no app context is currently active.