yera.runtime.handlers.base

Abstract base class for Yera event handlers.

Symbols

class BaseHandler — Abstract base for all Yera event handlers.

BaseHandler

Inherits: ABC

Abstract base for all Yera event handlers.

Each handler is responsible for processing events of a single block type. Handlers are used as context managers so that stateful implementations (e.g. a streaming markdown handler managing a live display) can acquire and release resources around a block. The default __enter__ and __exit__ are no-ops; override them only when setup or teardown is required.

Methods

bind_parent — Attach the handler owning this block's parent, if any.
__enter__ — Enter the handler context. No-op by default.
__exit__ — Exit the handler context. No-op by default.
push — Handle an event.

BaseHandler.bind_parent

bind_parent(
    parent: BaseHandler | None,
) → None

Attach the handler owning this block's parent, if any.

Called by the router once, before __enter__. None at top level or when the parent block has already closed.

Parameters

parent
type: BaseHandler | None

The enclosing block's handler.

BaseHandler.__enter__

__enter__() → Self

Enter the handler context. No-op by default.

BaseHandler.__exit__

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

Exit the handler context. No-op by default.

BaseHandler.push

push(
    event: OutputEvent,
) → None

Handle an event.

Called once per event in the block, in order. Stateful handlers accumulate state across repeated calls within a single context manager scope.

Parameters

event
type: OutputEvent

The output event to handle.