fix: type the lists and returns mypy flagged

The data tree record carries the needed flag since 072380c26, and
the manifest test still built the three-part one. profile_sync's triage
lists and _emit's returns, site_insights' GoatCounter answers and
make_demo's blocks are annotated, and the baseline loses the entry
that no longer occurs.
This commit is contained in:
Abdessamad Derraz committed 2026-11-06 22:30:55 +01:00
1 parent 5730380d12
commit ae7feba539
5 files changed
+13 -9

No files matched your search

-1
View File
@@ -903,7 +903,6 @@ scripts/sect233r1.py:0: error: Incompatible types in assignment (expression has
scripts/site_insights.py:0: error: Item "list[Any]" of "Union[dict[Any, Any], list[Any]]" has no attribute "get" [union-attr]
scripts/site_insights.py:0: error: Item "list[Any]" of "Union[dict[Any, Any], list[Any]]" has no attribute "get" [union-attr]
scripts/site_insights.py:0: error: Item "list[Any]" of "Union[dict[Any, Any], list[Any]]" has no attribute "get" [union-attr]
scripts/site_insights.py:0: error: Item "list[Any]" of "Union[dict[Any, Any], list[Any]]" has no attribute "get" [union-attr]
scripts/sitediagrams.py:0: error: "AST" has no attribute "value" [attr-defined]
scripts/sitediagrams.py:0: error: Argument 1 to "lstrip" of "bytes" has incompatible type "str"; expected "Optional[Buffer]" [arg-type]
scripts/sitediagrams.py:0: error: If x = b'abc' then f"{x}" or "{}".format(x) produces "b'abc'", not "abc". If this is desired behavior, use f"{x!r}" or "{!r}".format(x). Otherwise, decode the bytes [str-bytes-safe]
+2 -1
View File
@@ -89,7 +89,8 @@ VIDEO_FPS = 25
def game_bytes(name: str) -> bytes:
"""Bytes of a game no catalog names, the same on every run."""
seed = hashlib.sha256(name.encode("utf-8")).digest()
blocks, counter = [], 0
blocks: list[bytes] = []
counter = 0
while len(blocks) * 32 < GAME_BYTES:
blocks.append(hashlib.sha256(seed + counter.to_bytes(4, "big")).digest())
counter += 1
+6 -5
View File
@@ -5018,7 +5018,7 @@ def _print_triage(
) -> bool:
"""Profiles ranked by drift, worst first. False when Ctrl-C cut the
scoring short: the ranking then covers the profiles scored."""
ranked = []
ranked: list[tuple[int, ProfileReport, str]] = []
sampled = 0
progress = _Progress(len(reports), "scored", args.offline or len(reports) < 2)
complete = True
@@ -5299,7 +5299,7 @@ def main() -> None:
raise SystemExit(1)
return
reports = []
reports: list[ProfileReport] = []
quiet = args.offline or len(selected) < 2
if not quiet:
print(
@@ -5474,18 +5474,18 @@ def _emit(
triage was cut short."""
if args.as_json:
print(json.dumps([report_to_dict(r) for r in shown], indent=2))
return
return None
if args.markdown:
target = Path(args.report_dir) / f"profile-sync-{date.today().isoformat()}.md"
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(format_markdown(shown), encoding="utf-8")
print(f"written: {target}")
return
return None
if args.fetch_plan:
for report in shown:
for url in fetch_plan(report):
print(url)
return
return None
if args.triage:
return _print_triage(args, selected, shown)
for report in shown:
@@ -5494,6 +5494,7 @@ def _emit(
print()
if args.changed_only:
_print_elided(reports, len(shown), frozenset(report.name for report in shown))
return None
def _print_elided(
+3 -1
View File
@@ -123,7 +123,7 @@ def fetch_queries(start: dt.date, end: dt.date) -> list[Query]:
return rows
def fetch_goatcounter(start: dt.date, end: dt.date) -> dict[str, list[tuple[str, int]]]:
def fetch_goatcounter(start: dt.date, end: dt.date) -> dict:
"""Paths and events with their visit counts, and the referring domains."""
token = (CONFIG / "goatcounter-api-token.txt").read_text(encoding="utf-8").strip()
auth = {"Authorization": f"Bearer {token}"}
@@ -140,6 +140,8 @@ def fetch_goatcounter(start: dt.date, end: dt.date) -> dict[str, list[tuple[str,
break
refs = _get_json(f"{GOATCOUNTER}/stats/toprefs?{urllib.parse.urlencode({**span, 'limit': 50})}", auth)
total = _get_json(f"{GOATCOUNTER}/stats/total?{urllib.parse.urlencode(span)}", auth)
if not isinstance(refs, dict) or not isinstance(total, dict):
raise SystemExit("GoatCounter answered with something other than an object")
# An action carries no referrer, and GoatCounter files it as a direct
# visit: 592 of the first day's 1,145 "direct" were clicks.
events = int(total.get("total_events", 0))
+2 -1
View File
@@ -318,11 +318,12 @@ class TheManifestCarriesTheArchiveSize(unittest.TestCase):
registry = {ref: {"source_type": "zip", "source_url": f"https://x/{ref}.zip",
"local_cache": str(data / ref)} for ref in ("pak", "old")}
members = [(str(data / ref / "a.bin"), f"{ref}/a.bin") for ref in ("pak", "old")]
refs = {f"{ref}/a.bin": (ref, ("s",), ref) for ref in ("pak", "old")}
refs = {f"{ref}/a.bin": (ref, ("s",), ref, True) for ref in ("pak", "old")}
listed = {entry["ref"]: entry for entry in
_manifest_data_directories(members, refs, registry, "")}
self.assertEqual(listed["pak"]["archive_size"], 21_360_579)
self.assertNotIn("archive_size", listed["old"])
self.assertNotIn("optional", listed["pak"])
if __name__ == "__main__":