From 81880e85381b5725c47877cd0a81111fef2881ee Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 27 Jun 2022 17:23:08 +0200 Subject: [PATCH] EventListener: key global dict by modulepath+clsname instead of clsname follow-up https://github.com/spesmilo/electrum/commit/fe74e4b9c95cc6e83056dd630c6f824830ee57a3 Just for sanity -- there could be a collision of class names (defined in separate modules). ``` >>> wallet.is_up_to_date.__qualname__ 'Abstract_Wallet.is_up_to_date' >>> wallet.is_up_to_date.__module__ 'electrum.wallet' ``` --- electrum/util.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/electrum/util.py b/electrum/util.py index a351cb67b..111911c96 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -1631,15 +1631,15 @@ callback_mgr = CallbackManager() trigger_callback = callback_mgr.trigger_callback register_callback = callback_mgr.register_callback unregister_callback = callback_mgr.unregister_callback -_event_listeners = defaultdict(set) +_event_listeners = defaultdict(set) # type: Dict[str, Set[str]] class EventListener: def _list_callbacks(self): for c in self.__class__.__mro__: - classname = c.__name__ - for method_name in _event_listeners[classname]: + classpath = f"{c.__module__}.{c.__name__}" + for method_name in _event_listeners[classpath]: method = getattr(self, method_name) assert callable(method) assert method_name.startswith('on_event_') @@ -1659,7 +1659,8 @@ class EventListener: def event_listener(func): classname, method_name = func.__qualname__.split('.') assert method_name.startswith('on_event_') - _event_listeners[classname].add(method_name) + classpath = f"{func.__module__}.{classname}" + _event_listeners[classpath].add(method_name) return func