diff options
author | mathieui <mathieui@mathieui.net> | 2021-03-14 22:31:22 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2021-04-02 17:44:36 +0200 |
commit | 4b198be9771594a28824cc082e737fe15ab681ec (patch) | |
tree | 01de648647136734d176ba0fa33e96a61bbafc88 /poezio/core/core.py | |
parent | bc4f4f1e0766aedb6b0e9f3df90fee9ea841786c (diff) | |
download | poezio-4b198be9771594a28824cc082e737fe15ab681ec.tar.gz poezio-4b198be9771594a28824cc082e737fe15ab681ec.tar.bz2 poezio-4b198be9771594a28824cc082e737fe15ab681ec.tar.xz poezio-4b198be9771594a28824cc082e737fe15ab681ec.zip |
fix: tons of type errors
Diffstat (limited to 'poezio/core/core.py')
-rw-r--r-- | poezio/core/core.py | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/poezio/core/core.py b/poezio/core/core.py index 93ea5c5b..91c9b3cc 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -16,6 +16,7 @@ import time import uuid from collections import defaultdict from typing import ( + Any, cast, Callable, Dict, @@ -233,9 +234,9 @@ class Core: '_dnd': lambda: self.command.status('dnd'), '_xa': lambda: self.command.status('xa'), ##### Custom actions ######## - '_exc_': self.try_execute, } self.key_func.update(key_func) + self.key_func.try_execute = self.try_execute # Add handlers xmpp_event_handlers = [ @@ -796,12 +797,14 @@ class Core: def remove_timed_event(self, event: DelayedEvent) -> None: """Remove an existing timed event""" - event.handler.cancel() + if event.handler is not None: + event.handler.cancel() def add_timed_event(self, event: DelayedEvent) -> None: """Add a new timed event""" event.handler = asyncio.get_event_loop().call_later( - event.delay, event.callback, *event.args) + event.delay, event.callback, *event.args + ) ####################### XMPP-related actions ################################## @@ -1174,6 +1177,7 @@ class Core: provided, we open a StaticConversationTab, else a DynamicConversationTab """ + new_tab: tabs.ConversationTab if jid.resource: new_tab = tabs.StaticConversationTab(self, jid) else: @@ -1196,19 +1200,19 @@ class Core: self.tabs.set_current_tab(tab) return tab # create the new tab - tab = self.tabs.by_name_and_class(room_name, tabs.MucTab) - if not tab: + muc_tab = self.tabs.by_name_and_class(room_name, tabs.MucTab) + if not muc_tab: return None - new_tab = tabs.PrivateTab(self, complete_jid, tab.own_nick) + tab = tabs.PrivateTab(self, complete_jid, muc_tab.own_nick) if hasattr(tab, 'directed_presence'): - new_tab.directed_presence = tab.directed_presence + tab.directed_presence = tab.directed_presence if not focus: - new_tab.state = "private" + tab.state = "private" # insert it in the tabs - self.add_tab(new_tab, focus) + self.add_tab(tab, focus) self.refresh_window() - tab.privates.append(new_tab) - return new_tab + muc_tab.privates.append(tab) + return tab def open_new_room(self, room: str, @@ -1764,18 +1768,23 @@ class Core: self.refresh_window() -class KeyDict(dict): +class KeyDict(Dict[str, Callable[[str], Any]]): """ A dict, with a wrapper for get() that will return a custom value if the key starts with _exc_ """ + try_execute: Optional[Callable[[str], Any]] def get(self, key: str, default: Optional[Callable] = None) -> Callable: if isinstance(key, str) and key.startswith('_exc_') and len(key) > 5: - return lambda: dict.get(self, '_exc_')(key[5:]) + if self.try_execute is not None: + try_execute = self.try_execute + return lambda: try_execute(key[5:]) + raise ValueError("KeyDict not initialized") return dict.get(self, key, default) + def replace_key_with_bound(key: str) -> str: """ Replace an inputted key with the one defined as its replacement |