From e1795d584ebd9b81173a150541aa99764f3b6a38 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 6 Nov 2026 19:58:08 +0100 Subject: [PATCH] fix: type the goatcounter totals for mypy 4ac3f7de7 read .get on _get_json's dict | list answer, four errors past mypy-baseline.txt. --- scripts/site_insights.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/site_insights.py b/scripts/site_insights.py index f9edc0bfa..f10192b2e 100644 --- a/scripts/site_insights.py +++ b/scripts/site_insights.py @@ -41,6 +41,7 @@ import urllib.request from collections import defaultdict from dataclasses import dataclass from pathlib import Path +from typing import Any, cast sys.path.insert(0, os.path.dirname(__file__)) from common import github_token, load_database, load_emulator_profiles, run_cli @@ -123,7 +124,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[str, Any]: """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}"} @@ -138,8 +139,8 @@ def fetch_goatcounter(start: dt.date, end: dt.date) -> dict[str, list[tuple[str, exclude.append(str(hit["path_id"])) if not answer.get("more"): 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) + refs = cast(dict, _get_json(f"{GOATCOUNTER}/stats/toprefs?{urllib.parse.urlencode({**span, 'limit': 50})}", auth)) + total = cast(dict, _get_json(f"{GOATCOUNTER}/stats/total?{urllib.parse.urlencode(span)}", auth)) # 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))