chore: clear typehinting errors

This commit is contained in:
aclist 2026-05-14 16:15:22 +09:00
parent ea1b9facd2
commit 2ebe8cad84
9 changed files with 35 additions and 27 deletions

View File

@ -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

View File

@ -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

View File

@ -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":

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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()