chore: clear typehinting errors

This commit is contained in:
aclist committed 2026-05-15 23:26:47 +09:00
1 parent 2d265c4b9b
commit 156c1f8ec4
16 files changed
+83 -85

No files matched your search

+6 -3
View File
@@ -70,8 +70,11 @@ def parse_meta(file: Path) -> ModMeta | None:
if ntok == "-":
ntok += str(lex.get_token())
elif tok == "name":
ntok = lex.get_token().split('"')[1]
v.append(ntok)
ntok = lex.get_token()
if ntok is not None:
ntok = ntok.split('"')[1]
if ntok is not None:
v.append(ntok)
meta = ModMeta(*v)
return meta
@@ -99,7 +102,7 @@ def get_delimited_mods(steam_path: Path) -> list[Any]:
size = get_mod_size(mod)
# NOTE: final col is cell renderer highlight toggle
clean.append([meta.name, symlink, mod_dir, size, False])
clean.sort(key=lambda row: row[0].casefold())
clean.sort(key=lambda row: str(row[0]).casefold())
return clean
+3 -8
View File
@@ -431,20 +431,15 @@ def get_app_path(folders_path: Path, appid: int) -> Path:
for obj in j["libraryfolders"]:
if str(appid) in j["libraryfolders"][obj]["apps"]:
app_path = j["libraryfolders"][obj]["path"]
break
if Path(app_path).exists():
break
if app_path is None:
raise AppNotInstalledError(
f"Failed to find a libraryfolder for the appid {appid}"
)
app_path = Path(app_path)
if app_path.exists() is False:
raise AppMovedError(
f"Path '{app_path}' specified in libraryfolders does not exist"
)
return app_path
return Path(app_path)
def get_pretty_version(steam_path: Path, appid: int) -> str | None:
+14 -3
View File
@@ -86,7 +86,11 @@ class A2SInfo:
raise AttributeError("No record to convert")
ip = self.record.ip
qport = self.record.qport
return source_info_to_dict(ip, qport, self.info)
try:
return source_info_to_dict(ip, qport, self.info)
except Exception as e:
logger.warning(e)
raise e
def is_modded(self) -> bool:
if self.info is None:
@@ -239,7 +243,7 @@ def parse_json(json: list) -> list:
return rows
def source_info_to_dict(ip: str, qport: int, info: "SourceInfo") -> dict[str, Any] | None:
def source_info_to_dict(ip: str, qport: int, info: "SourceInfo") -> dict[str, Any]:
try:
name = info.server_name
mapname = info.map_name
@@ -268,7 +272,7 @@ def source_info_to_dict(ip: str, qport: int, info: "SourceInfo") -> dict[str, An
except Exception as e:
# TODO: generalized function
logger.critical(f"{type(e).__name__}: {e} ({ip}:{qport})")
return None
raise e
def query_direct(ip: str, qport: int, timeout: float = 3.0) -> dict[str, Any] | None:
@@ -448,6 +452,8 @@ def get_rules(record: Record) -> list["DayzMod"]:
def query_playercount(record: Record) -> tuple[int, int] | None:
try:
res = query_direct(record.ip, record.qport)
if res is None:
return None
players = int(res["players"])
r = res["gametype"].split("lqs")
try:
@@ -462,6 +468,8 @@ def query_playercount(record: Record) -> tuple[int, int] | None:
def query_by_ip(addr: str) -> A2SInfo:
record = short_ip_to_record(addr)
if record is None:
return A2SInfo(Record("0", 0, 0), None)
return query_by_record(record, update_gameport=True)
def query_by_id(server_id: int, key: str) -> A2SInfo:
@@ -469,6 +477,8 @@ def query_by_id(server_id: int, key: str) -> A2SInfo:
Used with numeric Battlemetrics IDs
"""
record = map_id_to_record(key, server_id)
if record is None:
return A2SInfo(Record("0", 0, 0), None)
return query_by_record(record)
@@ -485,6 +495,7 @@ def query_by_record(record: Record, update_gameport: bool = False) -> A2SInfo:
def short_ip_to_record(addr: str) -> Optional[Record]:
r = addr.split(":")
# TODO: raise exceptions instead of Nonetype
if len(r) != 2:
return None
return Record(r[0], 0, int(r[1]))
+10 -7
View File
@@ -141,7 +141,8 @@ def vdf2json(path: Path) -> str:
indent -= 1
jbuf += _istr(indent, "}")
ntok = lex.get_token()
lex.push_token(ntok)
if ntok is not None:
lex.push_token(ntok)
if ntok and ntok != "}":
jbuf += ","
jbuf += "\n"
@@ -151,12 +152,14 @@ def vdf2json(path: Path) -> str:
jbuf += _istr(indent, tok + ": {\n")
indent += 1
else:
jbuf += _istr(indent, tok + ": " + ntok)
ntok = lex.get_token()
lex.push_token(ntok)
if ntok != "}":
jbuf += ","
jbuf += "\n"
if ntok is not None:
jbuf += _istr(indent, tok + ": " + ntok)
ntok = lex.get_token()
if ntok is not None:
lex.push_token(ntok)
if ntok != "}":
jbuf += ","
jbuf += "\n"
def gen_shortcut() -> None: