Event¶
-
class
narupatools.core.event.Event(callback_type: Optional[Type[TEventCallback]] = None)¶ Class which stores a set of callbacks, which are invoked when an event is published.
The narupatools version of Event performs some simple type checking, to ensure that callbacks support all the parameters that this event produces. It also prints a warning if an added callback does not handle generic
**kwargs, which is good practise that future proof callbacks.Inheritance

Methods
Create a new event, optionally passing a type that represents the callback.
Add a callback to this event.
Remove a callback from this event.
-
__init__(callback_type: Optional[Type[TEventCallback]] = None) → None¶ Create a new event, optionally passing a type that represents the callback.
- Parameters
callback_type – Desired type of the callback. If this has a
__call__method, the named arguments of this will be stored. Adding a callback to this event which cannot handle all these named parameters (either directly or by using**kwargs) will raise an exception.
-
add_callback(callback: TEventCallback) → None¶ Add a callback to this event.
- Parameters
callback – The callback to be called when this event is triggered.
- Raises
CallbackMissingParametersError – Callback is missing one or more keyword arguments the event uses.
-
remove_callback(callback: TEventCallback) → None¶ Remove a callback from this event.
This operation is atomic, and will not fail if
callbackis not listening to this event.- Parameters
callback – The callback to be removed from this event’s callbacks
Attributes
Invoke the callbacks associated with this event with the provided arguments.
-
invoke¶ Invoke the callbacks associated with this event with the provided arguments.
This is implemented as a property which returns the function that should then be invoked. This is so the invoke function can be correctly typed, and allows IDE’s to autocomplete arguments correctly.
-