Skip to content

ci: extend mypy to bench/ and scripts/, fix a real type error it finds - #130

Open
shrdgn wants to merge 1 commit into
mainfrom
claude/mypy-scope-bench-scripts
Open

ci: extend mypy to bench/ and scripts/, fix a real type error it finds#130
shrdgn wants to merge 1 commit into
mainfrom
claude/mypy-scope-bench-scripts

Conversation

@shrdgn

@shrdgn shrdgn commented Aug 2, 2026

Copy link
Copy Markdown
Owner

What & why

CI's mypy step (and pyproject.toml's [tool.mypy]) only ever scoped to openfusion/. The repo also ships non-trivial, non-test Python in bench/ (the benchmark harness) and scripts/ (the OpenRouter smoke test) that got zero static type checking.

Running mypy bench/ scripts/ --ignore-missing-imports surfaces a real bug today: bench/run.py::_chat() is annotated to return tuple[str, float, dict[str, Any]], but the usage value it actually returns typed as Any | dict[Any, Any] | None — the isinstance narrowing was applied to a throwaway payload.get("usage") call rather than to the value actually returned, so the annotation wasn't backed by anything. Fixed by binding the raw value to a variable first, then narrowing that same variable.

CI now runs mypy openfusion/ bench/ scripts/ ... so this class of bug is caught going forward instead of only being visible to a human who happens to run mypy against those directories manually.

Note: this touches the same ci.yml mypy line as the other currently-open PR "fix: resolve mypy config drift between pyproject.toml and CI" (different scope — that one reconciles CLI flags vs. pyproject.toml's [tool.mypy] for openfusion/ itself; this one widens which directories get checked and fixes a bug the widening finds). Whichever merges second will need a small, mechanical rebase of that one line.

How it was tested

  • ruff check . passes
  • mypy openfusion/ bench/ scripts/ --ignore-missing-imports --disable-error-code import-untyped --exclude openfusion/cli.py passes (0 errors, was 1 error before the fix)
  • pytest -q passes (existing tests/test_bench*.py still pass unchanged)
  • New behavior has a test — N/A, this is a type-correctness fix with existing test coverage on _chat's behavior; no runtime behavior changed
  • Docs updated — CHANGELOG.md "Fixed" entry added
  • No secrets, prompts, or response bodies added to logs or metrics
  • N/A — no quality/cost bench claim

Notes for reviewers

bench/run.py and scripts/openrouter_smoke.py were already clean under ruff check .; this PR only adds mypy coverage and fixes the one issue it surfaces. No runtime behavior changes.


Generated by Claude Code

CI's mypy step only ever checked openfusion/, so bench/ and scripts/
(both shipped, non-trivial Python) got zero static type checking.
Extending the check immediately surfaces a real bug: bench/run.py's
_chat() helper returned a usage value typed Any | dict[Any, Any] | None
against a tuple[str, float, dict[str, Any]] return annotation, because
the isinstance narrowing was applied to a throwaway payload.get() call
rather than the value actually returned. Fixed by narrowing a bound
variable instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013gp2rKKYP4qAFGgrX8cXLg
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.

2 participants