diff --git a/mypy-baseline.txt b/mypy-baseline.txt index 6aed090c2..bf132120b 100644 --- a/mypy-baseline.txt +++ b/mypy-baseline.txt @@ -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] diff --git a/scripts/make_demo.py b/scripts/make_demo.py index 570b1b1cf..2bc1dd289 100644 --- a/scripts/make_demo.py +++ b/scripts/make_demo.py @@ -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 diff --git a/scripts/profile_sync.py b/scripts/profile_sync.py index 16e47ffba..b72787608 100644 --- a/scripts/profile_sync.py +++ b/scripts/profile_sync.py @@ -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( diff --git a/scripts/site_insights.py b/scripts/site_insights.py index f9edc0bfa..d55a8312f 100644 --- a/scripts/site_insights.py +++ b/scripts/site_insights.py @@ -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)) diff --git a/tests/test_refresh_data_dirs.py b/tests/test_refresh_data_dirs.py index 604eba7ba..963a7e1fb 100644 --- a/tests/test_refresh_data_dirs.py +++ b/tests/test_refresh_data_dirs.py @@ -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__":