ci: extend mypy to openfusion/cli.py, fix the type errors it finds - #147
Open
shrdgn wants to merge 1 commit into
Open
ci: extend mypy to openfusion/cli.py, fix the type errors it finds#147shrdgn wants to merge 1 commit into
shrdgn wants to merge 1 commit into
Conversation
cli.py was the only module in openfusion/ excluded from mypy (both pyproject.toml and the CI workflow). Running it directly surfaced two real issues: _chat_turn's console: object | None param defeated attribute checking on every console.print/console.status call in its Rich-rendering branch, and a content variable was redefined with a conflicting type across that branch and the plain-text branch. Typed console as Console | None via a TYPE_CHECKING-only import (rich's runtime import stays lazy) and renamed the second content to answer. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SfTJhjkqkDfTMzufuBcLtQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
openfusion/cli.py— the CLI/REPL entrypoint, and at 510+ lines the largest hand-writtenmodule in
openfusion/— was the only module in the package excluded from mypy, in bothpyproject.toml's[tool.mypy](exclude = ["openfusion/cli\\.py"]) and the CI workflow'sown
--exclude openfusion/cli.pyflag. Running mypy on it directly (as CI never does)immediately surfaces two real issues, both in
_chat_turn's Rich-rendering branch:console: object | None = None(the function's third param) is typed as bareobjectinstead of
rich.console.Console | None, which defeats attribute checking on everyconsole.status(...)/console.print(...)call in the branch that uses it. A real typo inone of those calls (e.g. a renamed Rich API) would go uncaught by mypy and only surface when
someone actually ran
openfusion chatinteractively.contentvariable is assigned in the plain-text branch (content, _ = majority_vote(panel)at what's now line 219) and then re-declared with an explicit
str | Noneannotation in theRich-rendering branch below it (line 238) — a redefinition-with-conflicting-type mypy flags
even though the two branches are mutually exclusive at runtime (the first branch always
returns before the second is reached).Fix
TYPE_CHECKING-onlyfrom rich.console import Consoleimport and typed the paramas
Console | None.richis already a hard (non-optional) dependency(
pyproject.toml'sdependencies), and the file already doesfrom __future__ import annotations, so this adds zero runtime import cost — the existing lazyfrom rich.console import Consoleinsiderun_chat(kept for CLI startup latency on non-chat subcommands) isuntouched.
contenttoanswerto remove the redefinition.cli.pyexclude from bothpyproject.tomland.github/workflows/ci.yml'smypystep.Not touched:
[tool.coverage.run]'s separateomit = [..., "openfusion/cli.py"]— that'sabout
pytest --cov, notmypy, and its own comment explains a different, still-validrationale (TTY/stdin mocking noise) unrelated to this change.
How it was tested
ruff check .passespytest -qpasses (490 passed, no live network — no new tests needed, this is atype-only change with no runtime behavior difference)
mypy openfusion/ --ignore-missing-imports --disable-error-code import-untyped(theexact CI invocation, now scope-widened) —
Success: no issues found in 25 source filesNotes for reviewers
Found via an automated repo-review scheduled task; verified by hand by running mypy against
cli.pydirectly (bypassing the exclude) and confirming it was the only module inopenfusion/carrying one, in both places it's configured.Generated by Claude Code