From 5c81f77b5dc1a79680c7dfb363a3f2bb6efca917 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 25 Oct 2024 16:58:47 +0000 Subject: [PATCH] util: add docstring to EventListener --- electrum/util.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/electrum/util.py b/electrum/util.py index c480eaee4..870182fe5 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -1844,6 +1844,11 @@ _event_listeners = defaultdict(set) # type: Dict[str, Set[str]] class EventListener: + """Use as a mixin for a class that has methods to be triggered on events. + - Methods that receive the callbacks should be named "on_event_*" and decorated with @event_listener. + - register_callbacks() should be called exactly once per instance of EventListener, e.g. in __init__ + - unregister_callbacks() should be called at least once, e.g. when the instance is destroyed + """ def _list_callbacks(self): for c in self.__class__.__mro__: @@ -1866,6 +1871,7 @@ class EventListener: def event_listener(func): + """To be used in subclasses of EventListener only. (how to enforce this programmatically?)""" classname, method_name = func.__qualname__.split('.') assert method_name.startswith('on_event_') classpath = f"{func.__module__}.{classname}"