2.6 KiB
signals
Signals and SignalEmitter that gathers the signals on models Meta. Used to signal receivers functions about events, i.e. post_save, pre_delete etc.
__all__
signals.signal
callable_accepts_kwargs
callable_accepts_kwargs(func: Callable) -> bool
Checks if function accepts **kwargs.
Arguments:
func (function): function which signature needs to be checked
Returns:
(bool): result of the check
make_id
make_id(target: Any) -> Union[int, Tuple[int, int]]
Creates id of a function or method to be used as key to store signal
Arguments:
target (Any): target which id we want
Returns:
(int): id of the target
Signal Objects
class Signal()
Signal that notifies all receiver functions. In ormar used by models to send pre_save, post_save etc. signals.
__init__
| __init__() -> None
connect
| connect(receiver: Callable) -> None
Connects given receiver function to the signal.
Raises:
SignalDefinitionError: if receiver is not callable or not accept **kwargs
Arguments:
receiver (Callable): receiver function
disconnect
| disconnect(receiver: Callable) -> bool
Removes the receiver function from the signal.
Arguments:
receiver (Callable): receiver function
Returns:
(bool): flag if receiver was removed
send
| async send(sender: Type["Model"], **kwargs: Any) -> None
Notifies all receiver functions with given kwargs
Arguments:
sender (Type["Model"]): model that sends the signalkwargs (Any): arguments passed to receivers
SignalEmitter Objects
class SignalEmitter()
Emitter that registers the signals in internal dictionary. If signal with given name does not exist it's auto added on access.
__init__
| __init__() -> None
__getattr__
| __getattr__(item: str) -> Signal
__setattr__
| __setattr__(key: str, value: Any) -> None