Skip to content

Clear all 16 mypy errors in record_keeper.py (#431 session 3) - #440

Merged
squid-protocol merged 1 commit into
mainfrom
fix/431-record-keeper-folder-stats-typing
Jul 25, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/431-record-keeper-folder-stats-typing

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Part of #429/#431, one file per session. This session: `record_keeper.py`.

Two distinct fixes:

  • `folder_stats` mixes `int`, `float`, and `List[float]` values in one dict literal, widened by mypy to `object` -- producing a cascade of `append`/operator/`sum`/`max`/`round` errors everywhere the accumulated stats get consumed. Added a `FolderStats` `TypedDict`. Resolved 15/16.
  • `ai_score` is first assigned as a bare `float`, then reassigned to `None` in the `zero_dependency_mode` branch -- intentional (record_keeper already maps bypassed zero-dep metrics to real SQL `NULL` rather than `0.0`, specifically so an unavailable metric doesn't look like a measured "zero risk" -- see `e7e1acff`). Annotated `Optional[float]` at first assignment. The other five zero-dep-branch variables (`pagerank_score`, `blast_radius`, etc.) already infer `Optional[float]` cleanly with no prior binding, so needed no change.

173 → 157 unique baseline entries.

Test plan

  • `record_keeper.py` reports zero mypy errors after this change
  • Baseline regenerated in the minimal env `mypy-audit.yml` actually uses
  • `flake8`, `dead_key_audit.py --ci`, full `pytest tests/` (866 passed, 1 deselected, 1 pre-existing xfail) all clean

Two distinct fixes:

- `folder_stats: Dict[str, FolderStats] = {}`: the per-folder rollup
  accumulator mixes int, float, and List[float] values in one dict
  literal, which mypy widened to "object" -- producing a cascade of
  "object has no attribute append", "Unsupported operand types for +",
  and "No overload variant of sum/max/round matches" errors everywhere
  the accumulated stats get consumed. Added a FolderStats TypedDict
  declaring each field's real type instead. Resolved 15 of 16.

- `ai_score`: first assigned as a bare float (from `float(str(...))`
  or a `0.0` fallback), then later reassigned to None in the
  zero_dependency_mode branch -- that None is intentional (record_keeper
  already maps bypassed zero-dep metrics to real SQL NULL rather than
  0.0, specifically to avoid an unavailable metric looking like a
  measured "zero risk" in the database -- see e7e1acf). Annotated
  `Optional[float]` at first assignment instead of changing the None.
  pagerank_score/blast_radius/betweenness_score/closeness_score/
  producer_ratio/ecosystem_role already infer Optional[float] cleanly
  from the same if/else with no prior binding, so they needed no change.

173 -> 157 unique baseline entries. Regenerated in the minimal
mypy-audit.yml environment per #436's lesson.

Verified: record_keeper.py reports zero mypy errors after this change.
flake8, dead_key_audit.py --ci, full pytest suite (866 passed,
1 deselected, 1 pre-existing xfail) all clean.
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit d1c5c21 into main Jul 25, 2026
26 checks passed
@squid-protocol
squid-protocol deleted the fix/431-record-keeper-folder-stats-typing branch July 25, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant