refactor(build): remove StarData TypedDict, loosen load_stars return to dict[str, dict]

Cache-write shape mismatches the TypedDict and callers mix .get() and
direct access, so the stricter type was providing false safety. Using
dict[str, dict] accurately reflects the actual runtime contract.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-04-19 21:57:30 +08:00
parent 7f4a163534
commit 7e7de19ef6
+1 -10
View File
@@ -6,19 +6,10 @@ import re
import shutil import shutil
from datetime import UTC, datetime from datetime import UTC, datetime
from pathlib import Path from pathlib import Path
from typing import TypedDict
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
from readme_parser import ParsedGroup, ParsedSection, parse_readme, parse_sponsors from readme_parser import ParsedGroup, ParsedSection, parse_readme, parse_sponsors
class StarData(TypedDict):
stars: int
owner: str
last_commit_at: str
fetched_at: str
GITHUB_REPO_URL_RE = re.compile(r"^https?://github\.com/([^/]+/[^/]+?)(?:\.git)?/?$") GITHUB_REPO_URL_RE = re.compile(r"^https?://github\.com/([^/]+/[^/]+?)(?:\.git)?/?$")
SOURCE_TYPE_DOMAINS = { SOURCE_TYPE_DOMAINS = {
@@ -46,7 +37,7 @@ def extract_github_repo(url: str) -> str | None:
return m.group(1) if m else None return m.group(1) if m else None
def load_stars(path: Path) -> dict[str, StarData]: def load_stars(path: Path) -> dict[str, dict]:
"""Load star data from JSON. Returns empty dict if file doesn't exist or is corrupt.""" """Load star data from JSON. Returns empty dict if file doesn't exist or is corrupt."""
if path.exists(): if path.exists():
try: try: