diff --git a/mypy-baseline.txt b/mypy-baseline.txt index 71fc9d12f..6399b243c 100644 --- a/mypy-baseline.txt +++ b/mypy-baseline.txt @@ -899,6 +899,8 @@ scripts/scraper/targets/rocknix_targets_scraper.py:0: error: Name "github_header scripts/scraper/targets/rocknix_targets_scraper.py:0: error: Name "standalone_emulators" already defined (possibly by an import) [no-redef] scripts/sect233r1.py:0: error: Incompatible types in assignment (expression has type "Optional[tuple[int, int]]", variable has type "tuple[int, int]") [assignment] 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/profile_sync.py b/scripts/profile_sync.py index a4a34e3e7..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: list[tuple] = [] + ranked: list[tuple[int, ProfileReport, str]] = [] sampled = 0 progress = _Progress(len(reports), "scored", args.offline or len(reports) < 2) complete = True diff --git a/scripts/site_insights.py b/scripts/site_insights.py index 0bfb3701c..d55a8312f 100644 --- a/scripts/site_insights.py +++ b/scripts/site_insights.py @@ -123,15 +123,7 @@ def fetch_queries(start: dt.date, end: dt.date) -> list[Query]: return rows -def _get_object(url: str, headers: dict[str, str] | None = None) -> dict: - """A JSON answer that must be an object: GoatCounter's stats endpoints.""" - answer = _get_json(url, headers) - if not isinstance(answer, dict): - raise ValueError(f"{url} answered {type(answer).__name__}, not an object") - return answer - - -def fetch_goatcounter(start: dt.date, end: dt.date) -> dict[str, list[tuple[str, int]] | 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,14 +132,16 @@ def fetch_goatcounter(start: dt.date, end: dt.date) -> dict[str, list[tuple[str, exclude: list[str] = [] while True: params = urllib.parse.urlencode({**span, "limit": 100, "exclude_paths": ",".join(exclude)}) - answer = _get_object(f"{GOATCOUNTER}/stats/hits?{params}", auth) + answer = _get_json(f"{GOATCOUNTER}/stats/hits?{params}", auth) for hit in answer.get("hits", []): hits.append((hit["path"] + (" [404]" if hit.get("title") == "404" else ""), int(hit["count"]))) exclude.append(str(hit["path_id"])) if not answer.get("more"): break - refs = _get_object(f"{GOATCOUNTER}/stats/toprefs?{urllib.parse.urlencode({**span, 'limit': 50})}", auth) - total = _get_object(f"{GOATCOUNTER}/stats/total?{urllib.parse.urlencode(span)}", auth) + 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 525c622fd..963a7e1fb 100644 --- a/tests/test_refresh_data_dirs.py +++ b/tests/test_refresh_data_dirs.py @@ -323,6 +323,7 @@ class TheManifestCarriesTheArchiveSize(unittest.TestCase): _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__":