diff --git a/dzgui/api/bm.py b/dzgui/api/bm.py index 8e70bb2..c19a6eb 100644 --- a/dzgui/api/bm.py +++ b/dzgui/api/bm.py @@ -1,6 +1,6 @@ import logging import requests -from typing import Optional, TYPE_CHECKING +from typing import Any, Optional, TYPE_CHECKING from dzgui.const.constants import APP_NAME from dzgui.const.endpoints import BM_SERVERS @@ -11,7 +11,7 @@ if TYPE_CHECKING: from dzgui.api.servers import Record -def get_attributes(key: str, uid: int) -> str: +def get_attributes(key: str, uid: int) -> Any: # TODO: handle if key is not set # TODO: tests for malformed IDs/values diff --git a/dzgui/api/servers.py b/dzgui/api/servers.py index baca26c..33c602f 100644 --- a/dzgui/api/servers.py +++ b/dzgui/api/servers.py @@ -381,7 +381,7 @@ def ping(ip: str, qport: int) -> int: if res is None: return 9999 else: - return res["ping"] + return int(res["ping"]) except Exception: return 9999 diff --git a/dzgui/config/convert.py b/dzgui/config/convert.py index cbbc320..6aed650 100644 --- a/dzgui/config/convert.py +++ b/dzgui/config/convert.py @@ -50,7 +50,7 @@ def rc2json(file: Path) -> str: while True: tok = lex.get_token() - ntok = lex.get_token() + ntok: str | bool | None = lex.get_token() if ntok is not None: ntok = ntok.strip('""') @@ -58,7 +58,8 @@ def rc2json(file: Path) -> str: if tok in deprecated: continue elif tok in toggles: - ntok = str2bool(ntok) + if ntok is not None: + ntok = str2bool(ntok) elif tok == "preferred_client": tok = "client" elif tok == "api_key": diff --git a/dzgui/config/query.py b/dzgui/config/query.py index eb59cde..602b082 100644 --- a/dzgui/config/query.py +++ b/dzgui/config/query.py @@ -23,7 +23,7 @@ def lookup(path: Path, enum: Preferences) -> Any: return None -def get_config(path: Path) -> dict: +def get_config(path: Path) -> Any: # TODO: is this being called multiple times? try: json = read_json(path) @@ -37,7 +37,7 @@ def get_favorites(path: Path) -> list[str]: conf = get_config(path) except Exception: pass - return conf["ip_list"] + return list(conf["ip_list"]) # def is_in_favs(record: str, path: Path) -> bool: diff --git a/dzgui/config/xdg.py b/dzgui/config/xdg.py index 52ac6b9..2826a0b 100644 --- a/dzgui/config/xdg.py +++ b/dzgui/config/xdg.py @@ -54,7 +54,10 @@ def get_xdg_paths() -> dict: resolved_paths = {} for path in xdg_paths: rp = os.environ.get(path) - resolved_paths[path] = Path(rp) / APP_NAME_LOWER if is_writeable(rp) else xdg_paths[path] / APP_NAME_LOWER + if rp is not None and is_writeable(rp): + resolved_paths[path] = Path(rp) + else: + resolved_paths[path] = xdg_paths[path] / APP_NAME_LOWER return resolved_paths diff --git a/dzgui/model/model_factory.py b/dzgui/model/model_factory.py index 598327a..333db09 100644 --- a/dzgui/model/model_factory.py +++ b/dzgui/model/model_factory.py @@ -107,7 +107,7 @@ class FastInsertListStore(ListStore): for row in rows: self.append(row) - def append(self, row: list[Any] | tuple[Any, ...] | None = ...) -> TreeIter: + def append(self, row: list[Any] | tuple[Any, ...] | None = ...) -> TreeIter: # type: ignore # FIXME: argument cannot be none """ Optimized for speed, but makes no assurances about row homogeneity diff --git a/dzgui/views/components/buttonbox.py b/dzgui/views/components/buttonbox.py index b268c9e..3e056f6 100644 --- a/dzgui/views/components/buttonbox.py +++ b/dzgui/views/components/buttonbox.py @@ -13,7 +13,7 @@ logger = logging.getLogger(APP_NAME) if TYPE_CHECKING: from dzgui.const.enum import NotebookPage - from dzgui.controller.mc import Controller + from dzgui.controllers.mc import Controller from dzgui.controllers.emitter import Emitter diff --git a/dzgui/views/mixins/context_mixin.py b/dzgui/views/mixins/context_mixin.py index bfee8b9..66c6eed 100644 --- a/dzgui/views/mixins/context_mixin.py +++ b/dzgui/views/mixins/context_mixin.py @@ -93,7 +93,7 @@ class ContextMixin(TreeView): return False def _on_menu_click(self, widget: Gtk.MenuItem, enum: ContextMenu) -> None: - self.controller.menu_action(enum, self) + self.controller.menu_action(enum, self) # type: ignore def _on_key(self, menu: Gtk.Menu, event: Gdk.EventKey) -> bool | None: if not is_navkey(event.keyval): diff --git a/dzgui/views/trees/tree_base.py b/dzgui/views/trees/tree_base.py index 9603137..86cd5b9 100644 --- a/dzgui/views/trees/tree_base.py +++ b/dzgui/views/trees/tree_base.py @@ -67,6 +67,8 @@ class TreeView(CursorMixin, Gtk.TreeView): # type: ignore def get_focused_row_iter(self) -> Gtk.TreeIter: path = self.get_focused_row_path() model = self.get_model() + if model is None: + raise AttributeError("No model attached to tree") return model.get_iter(path) def get_focused_row_path(self) -> Gtk.TreePath: @@ -106,9 +108,10 @@ class TreeView(CursorMixin, Gtk.TreeView): # type: ignore # self.get_selection().select_iter(it) # return True - if self.get_model() is None: + model = self.get_model() + if model is None: return - if len(self.get_model()) < 2: + if len(model) < 2: return if is_navkey(event.keyval): if self.sel_blocked is True: @@ -144,7 +147,7 @@ class TreeView(CursorMixin, Gtk.TreeView): # type: ignore path = pathlist[0] tree_iter = model.get_iter(path) value = model.get_value(tree_iter, index) - return value + return str(value) def get_name(self) -> str: name = self.get_value_at_index(0) @@ -161,12 +164,12 @@ class TreeView(CursorMixin, Gtk.TreeView): # type: ignore return (model, pathlist) @deprecated("Currently unused") - def get_mpath(self) -> Optional[Gtk.TreePath]: - (model, pathlist) = self.get_model_and_pathlist() - if len(pathlist) < 1: - return None - path = pathlist[0] - return path + #def get_mpath(self) -> Optional[Gtk.TreePath]: + # (model, pathlist) = self.get_model_and_pathlist() + # if len(pathlist) < 1: + # return None + # path = pathlist[0] + # return path def _on_row_activated( self, @@ -182,13 +185,14 @@ class TreeView(CursorMixin, Gtk.TreeView): # type: ignore return True return False - def get_selected_row(self) -> Optional[Gtk.TreeModelRow]: - ind = self.get_selected_row_index() - model = self.get_model() - if model is None: - return None - row = model[ind] - return row + @deprecated("unused") + #def get_selected_row(self) -> Optional[Gtk.TreeModelRow]: + # ind = self.get_selected_row_index() + # model = self.get_model() + # if model is None: + # return None + # row = model[ind] + # return row def get_col_value_by_path_index(self, path: Gtk.TreePath, index: int) -> Any: model = self.get_model()