refactor: type the EOF-action seam with a sealed union#22
Merged
Conversation
Full-lane bundle 2026-06-26.03-type-eof-action-seam: replace the stringly-typed _detect_trailing/fix_file seam with a sealed union (Noop | AppendLf | Truncate) consumed by an exhaustive match; exhaustiveness enforced by ty via fix_file's bool return (no assert_never, 3.10-safe). Behavior-preserving; two-task plan with complete code. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a vendored `_assert_never(value: NoReturn) -> NoReturn` guard and a `case _: _assert_never(action)` wildcard arm in `fix_file`, so ty errors at the match site (not the return type) when a future `_EofAction` variant goes unhandled. Python 3.10 precludes `typing.assert_never` (3.11+); decision doc records the rationale and 2026-10-31 revisit trigger. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
A behavior-preserving deepening (architecture-review Candidate 2): replace the stringly-typed EOF-action seam in
eof_fixer/fixer.pywith a sealed union.Before:
_detect_trailing -> tuple[str, int]with magic strings"none"/"append_lf"/"truncate"and an offset meaningful only fortruncate;fix_filebranched on the strings with a comment-onlyelse: # truncate.After:
_detect_trailing -> _EofAction = Noop | AppendLf | Truncate(offset)(frozen dataclasses; offset only onTruncate— illegal states unrepresentable), consumed by an exhaustivematch. Magic strings and the dummy offset are gone. No behavior change.Exhaustiveness
The
matchis closed withcase _: _assert_never(action), pinning completeness at the match site: an unhandled future variant is a type error there (verified — ty reportsExpected Never, found <variant> & ~Noop & ~AppendLf & ~Truncate), not merely via the return type._assert_neveris vendored locally (def _assert_never(value: NoReturn) -> NoReturn) becausetyping.assert_neveris 3.11+ and the package supports 3.10. Rationale + revisit trigger recorded inplanning/decisions/2026-06-26-keep-py310-vendored-assert-never.md(revisit when 3.10 EOLs, 2026-10-31).Tests
Behavior-preserving, so existing tests stay green; added one coverage test (
test_check_mode_truncate_does_not_write) for theTruncate-under---checkbranch that the per-caseif not checksplit created. 36 passed, 100% coverage;just lint-ciclean (ruff select=["ALL"], ty).Planning artifacts (Full lane)
planning/changes/2026-06-26.03-type-eof-action-seam/planning/decisions/2026-06-26-keep-py310-vendored-assert-never.mdarchitecture/eof-normalization.mdBuilt via subagent-driven TDD (Task 1 review SHIP; final whole-branch review Ready to merge: Yes, which surfaced the structural-exhaustiveness subtlety now hardened here).
🤖 Generated with Claude Code