chore: clear typehinting errors

This commit is contained in:
aclist committed 2026-05-13 20:13:06 +09:00
1 parent fe0a6711f0
commit 866c88fbb0
14 files changed
+65 -43

No files matched your search

+2 -2
View File
@@ -33,8 +33,8 @@ def map_id_to_record(key: str, uid: int) -> Optional["Record"]:
try:
record = get_attributes(key, uid)
ip = record["ip"]
port = record["port"]
qport = record["portQuery"]
port = int(record["port"])
qport = int(record["portQuery"])
return Record(ip, port, qport)
except Exception:
return None
+3 -1
View File
@@ -49,7 +49,7 @@ def get_local_mods(workshop_path: Path) -> list[Path]:
return mods
def parse_meta(file: Path) -> ModMeta:
def parse_meta(file: Path) -> ModMeta | None:
mod = file / "meta.cpp"
if mod.exists() is False:
return None
@@ -135,6 +135,8 @@ def remove_stale_signatures(config: Path, versions: Path) -> None:
def find_stale_mods(config: Path) -> list[int]:
def push_record(rec: str) -> list:
record = fqip_to_record(rec)
if record is None:
return []
try:
mods = get_rules(record)
except Exception:
+12 -11
View File
@@ -33,35 +33,35 @@ class VersionMatch(Enum):
SAME_VERSION = 3
class u8:
class u8(int):
fmt = "B"
class u16:
class u16(int):
fmt = "H"
class u32:
class u32(int):
fmt = "L"
class u64:
class u64(int):
fmt = "Q"
class i8:
class i8(int):
fmt = "b"
class i16:
class i16(int):
fmt = "h"
class i32:
class i32(int):
fmt = "l"
class i64:
class i64(int):
fmt = "q"
@@ -330,6 +330,7 @@ def get_version(file: Path) -> FileVersion:
magic = hex(struct.unpack("<H", (blob[0:2]))[0])
f.seek(pos)
OBJW: OPTIONAL_HDR_WIN_X86 | OPTIONAL_HDR_WIN_X64
if magic == PE32_x86:
OPTIONAL_HDR_X86.unpack(f)
OBJW = OPTIONAL_HDR_WIN_X86.unpack(f)
@@ -363,7 +364,7 @@ def get_version(file: Path) -> FileVersion:
table = RESOURCE_DIRECTORY_TABLE.unpack(f)
total = table.number_of_name_entries + table.number_of_id_entries
for entry in range(total):
for _iter in range(total):
entry = RESOURCE_DIRECTORY_ENTRY.unpack(f)
if entry.name_or_id == VERSION_RESOURCE:
while entry.data_or_subdir & (1 << 31):
@@ -371,7 +372,7 @@ def get_version(file: Path) -> FileVersion:
seek_to_hex(hex(offset + shift), f)
table = RESOURCE_DIRECTORY_TABLE.unpack(f)
total = table.number_of_name_entries + table.number_of_id_entries
for entry in range(total):
for _iter in range(total):
entry = RESOURCE_DIRECTORY_ENTRY.unpack(f)
break
if entry.name_or_id > VERSION_RESOURCE:
@@ -383,7 +384,7 @@ def get_version(file: Path) -> FileVersion:
offset = data.data_rva - hdr.virtual_address + hdr.pointer_to_raw_data
seek_to_hex(hex(offset), f)
hdr = VS_VERSION_INFO_HDR.unpack(f)
VS_VERSION_INFO_HDR.unpack(f)
# https://learn.microsoft.com/en-us/windows/win32/menurc/vs-versioninfo
byte_len = len(VS_VERSION_INFO_ID.encode("utf-16le"))
label = f.read(byte_len).decode("utf-16le")
+3 -3
View File
@@ -81,9 +81,9 @@ class A2SInfo:
def get_info(self) -> a2s.SourceInfo | None:
return self.info
def as_row(self) -> dict[str, Any] | None:
def as_row(self) -> dict[str, Any]:
if self.info is None:
return None
raise AttributeError("No record to convert")
ip = self.record.ip
qport = self.record.qport
return source_info_to_dict(ip, qport, self.info)
@@ -239,7 +239,7 @@ def parse_json(json: list) -> list:
return rows
def source_info_to_dict(ip: str, qport: int, info: "SourceInfo") -> dict[str, Any]:
def source_info_to_dict(ip: str, qport: int, info: "SourceInfo") -> dict[str, Any] | None:
try:
name = info.server_name
mapname = info.map_name
+9 -9
View File
@@ -28,9 +28,9 @@ def get_local_signatures(version_file: Path) -> dict[str, int]:
hashes: dict[str, int] = {}
lines = version_file.read_text().splitlines()
for line in lines:
line = line.split(",")
_id = line[0]
_hash = int(line[1])
data = line.split(",")
_id = data[0]
_hash = int(data[1])
hashes[_id] = _hash
return hashes
@@ -49,7 +49,7 @@ def get_needs_update(
version_file: Path, remote_hashes: list[tuple[str, str, int, int]]
) -> list[tuple[str, str, int, int]]:
local_hashes = get_local_signatures(version_file)
needs_update: list[tuple[str, str]] = []
needs_update: list[tuple[str, str, int, int]] = []
for title, _id, _hash, size in remote_hashes:
if _id not in local_hashes:
needs_update.append((title, _id, _hash, size))
@@ -64,7 +64,7 @@ def get_remote_signatures(mods: list[str]) -> list[tuple[str, str, int, int]]:
"""
Attempts to continue connecting even if signatures are empty
"""
payload: dict[str, str] = {}
payload: dict[str, str | int] = {}
payload["itemcount"] = len(mods)
for i, mod in enumerate(mods):
payload[f"publishedfileids[{i}]"] = mod
@@ -76,13 +76,13 @@ def get_remote_signatures(mods: list[str]) -> list[tuple[str, str, int, int]]:
if r.status_code != 200:
return []
hashes: list[tuple[str, int, int]] = []
hashes: list[tuple[str, str, int, int]] = []
j = r.json()
rows = j["response"]["publishedfiledetails"]
for row in rows:
title = row["title"]
_id = row["publishedfileid"]
time = row["time_updated"]
title = str(row["title"])
_id = str(row["publishedfileid"])
time = int(row["time_updated"])
size = int(row["file_size"])
hashes.append((title, _id, time, size))
return hashes