Skip to content

xtr_event_dispatcher.decorator

Declaring listeners where they are written, for a container to register.

EventListenerDeclaration dataclass

EventListenerDeclaration(event: str | type | None = None, method: str | None = None, priority: int | None = None, dispatcher: str | None = None, before: tuple[OrderTarget, ...] = (), after: tuple[OrderTarget, ...] = ())

One @as_event_listener on a class, a method or a function.

Attributes:

  • event (str | type | None) –

    The event listened to; None reads it from the type of the listener's first parameter.

  • method (str | None) –

    The method to call; None on a class picks on_<event> or __call__, and on a function calls it.

  • priority (int | None) –

    The priority declared, None when none was.

  • dispatcher (str | None) –

    The named dispatcher to listen on; None for the default one.

  • before (tuple[OrderTarget, ...]) –

    Listeners this one must run before.

  • after (tuple[OrderTarget, ...]) –

    Listeners this one must run after.

listeners_declared_on

listeners_declared_on(obj: object) -> tuple[EventListenerDeclaration, ...]

Return every listener @as_event_listener declared on obj.

On a function, its own declarations. On a class, those on the class itself, then those on its methods — inherited, static and class methods included — each naming the method it sits on.

Raises:

  • InvalidListenerError –

    When a declaration on a method names a method to call: it is the method it sits on.