Skip to content

Stop reusing three variables for two types each - #371

Merged
alexarje merged 1 commit into
masterfrom
mypy-tail-4
Aug 23, 2026
Merged

Stop reusing three variables for two types each#371
alexarje merged 1 commit into
masterfrom
mypy-tail-4

Conversation

@alexarje

Copy link
Copy Markdown
Contributor

Continuing the tail of #350. mypy 50 → 45, 682 tests pass.

Ordinary inference debt this time rather than hidden failures — which is worth saying, because the earlier batches were not.

  • cmd_filter in _subtract was built as a filter string and then replaced by the two-element flag list carrying it.
  • weights_as_list in _history held the output of split() and then the floats parsed from it.
  • An unannotated accumulator.
  • type(weights) in [int, float] decides a branch but does not narrow. Narrowed with an isinstance assert rather than by rewriting the test: isinstance would start accepting bool, which type() in excludes on purpose, and narrowing for a type checker should not quietly widen what a function takes.

Verified by hand, since these touch real code paths rather than annotations: subtract() renders and writes its file, and history() works at its default, with string weights, and with a numeric weight.

Also found, filed separately

While reading this file I confirmed #370: motion_mp() raises on its first call, and behind that failure calls save_txt and save_analysis with arguments in the wrong slots. Pre-existing on master with a clean tree, not touched here.

Remaining after this: 45.

🤖 Generated with Claude Code

#350's tail: mypy 50 to 45. Ordinary inference debt this time rather than
hidden failures, which is itself worth noting --- the earlier batches were not.

`cmd_filter` in `_subtract` was built as a filter string and then replaced by
the two-element flag list that carries it; `weights_as_list` in `_history` held
the results of `split()` and then the floats parsed from them. Both now use a
second name, which is also what the code means.

The branch test `type(weights) in [int, float]` decides which arm runs but does
not narrow for a type checker. It is narrowed with an `isinstance` assert rather
than by rewriting the test, because `isinstance` would start accepting `bool`,
which `type() in` excludes on purpose. Narrowing for mypy should not quietly
widen what the function takes.

Verified by hand, since these touch real code paths rather than annotations:
`subtract()` renders and writes its file, and `history()` works at its default,
with string weights (the split-and-parse path) and with a numeric weight (the
narrowed branch).

682 tests pass, 4 skipped.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@alexarje
alexarje merged commit 1de5918 into master Aug 23, 2026
12 checks passed
@alexarje
alexarje deleted the mypy-tail-4 branch August 23, 2026 15:07
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