Skip to content

Fix: route check_release_tree.py's two deferred checkers through heredoc-aware tracking (#990) - #996

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/990
Oct 8, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/990

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Summary

Closes #990.

_check_catch_all_in_loop and _check_single_line_delegate_positional in .github/scripts/check_release_tree.py were the two checkers #980 deliberately left out of its _iter_non_heredoc_lines migration. Each docstring claimed the gap had been "filed for a follow-up rather than fixed silently alongside the other 16," but no such issue existed until #990 itself (checked at review time via issue search, and again during the curate pass that filed #990).

  • _check_single_line_delegate_positional now filters its extracted function-body string through _iter_non_heredoc_lines(body, track_heredocs=True) instead of a bare .startswith("#") test, so a heredoc attached to a function's single real statement no longer inflates the apparent line count and blinds the needle to it.
  • _check_catch_all_in_loop needed more care. A first attempt swapped its own enumerate(text.splitlines(), 1) loop for the shared generator directly, and that regressed in round-1 self-review: the generator's heredoc-open detection has no visibility into this function's own multi-line in_string state, so a <<WORD-shaped substring sitting inside a tracked quoted string was misread as a real heredoc opener and silently swallowed every later line -- including a genuine catch-all-in-loop -- as fake heredoc body. Fixed instead by tracking heredoc delimiters inline (the same regexes _iter_non_heredoc_lines itself uses: _mask_arithmetic, _HEREDOC_OPEN, _in_quotes_before), gated so detection only runs on a line that has already passed this function's own in_string/comment checks, so the two states can never step on each other.
  • Both docstrings now describe what was fixed and how, rather than naming a follow-up that no longer needs filing.

Review

Two review rounds, each a parallel Explore-reviewer + oss:auditor spawn pair:

  • Round 1 (against the first fix commit): the Explore reviewer found a real correctness regression in _check_catch_all_in_loop (the in_string/heredoc-open collision described above, verified empirically with a crafted fixture) and flagged the docstring's now-false claim about the two states interleaving safely. oss:auditor reported no findings across all classes. Both findings fixed in a follow-up commit.
  • Round 2 (against the fix-up commit, triggered by the repo's second-pass gate since 3 files were touched): both spawns reported no findings.

Test plan

  • Watched the new tests fail before each fix and pass after (shown separately for both commits)
  • python3 -m pytest tests/test_scanner_shapes_source_898.py tests/test_single_line_delegate_positional_905.py tests/test_heredoc_comment_guard_980.py -q -- 411 passed
  • Changelog fragment validated with .oss/assemble_changelog.py --check
  • Full CI matrix (ubuntu/macos/windows x Python 3.9-3.12) -- not run locally, per this repo's own CLAUDE.md guidance that CI is the gate

🤖 Generated with Claude Code

[AI-generated]

fdaviddpt and others added 2 commits October 8, 2026 10:26
…h the shared heredoc tracker

`_check_catch_all_in_loop` and `_check_single_line_delegate_positional`
were the two checkers #980 deliberately left out of its
`_iter_non_heredoc_lines` migration, but each docstring claimed the gap
was "filed for a follow-up" when no such issue existed until this one.

Routed both through the shared tracker: `_check_catch_all_in_loop` now
iterates `_iter_non_heredoc_lines(text, track_heredocs=True)` instead
of a raw `enumerate(text.splitlines(), 1)` -- the generator tracks
heredoc delimiters independently of the function's own multi-line
open/close-depth and in-string state, so the two interleave without
either needing to know about the other.
`_check_single_line_delegate_positional` now filters the extracted
function-body string through the same generator instead of a bare
`.startswith("#")` test, so a heredoc attached to a function's single
real statement no longer inflates the apparent line count and blinds
the needle to it.

Red test first in both tests/test_scanner_shapes_source_898.py and
tests/test_single_line_delegate_positional_905.py (2 failed before the
fix, 1 unaffected positive control passed); all 410 tests across the
two touched suites plus test_heredoc_comment_guard_980.py pass after.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…f-review

The Explore reviewer caught a real regression in the previous commit:
swapping _check_catch_all_in_loop's own enumerate(text.splitlines(), 1)
for the shared _iter_non_heredoc_lines generator directly fixed the
documented false-positive, but introduced a false negative. The
generator's heredoc-open detection runs on every line it yields with
no visibility into this function's own multi-line in_string state (a
tracked VAR='... single-quoted string), so a `<<WORD`-shaped substring
sitting inside the body of one of those tracked strings was misread
as a real heredoc opener and silently swallowed every later line --
including a genuine catch-all-in-loop -- as fake heredoc body.

Verified directly: running the committed (post-990) checker against a
crafted script with that shape returned no offenders, while running
the pre-990 (parent commit) checker against the same input correctly
flagged it.

Fixed by tracking heredoc delimiters inline instead of delegating to
the generator -- same regexes _iter_non_heredoc_lines itself uses
(_mask_arithmetic, _HEREDOC_OPEN, _in_quotes_before), but gated so
detection only runs on a line that already passed this function's own
in_string/comment checks, so the two states can never step on each
other. Docstring and changelog fragment corrected to describe the
actual approach rather than the claim the reviewer found false.

Red test (test_heredoc_open_syntax_inside_the_checkers_own_tracked_
string_does_not_blind_it) confirmed failing against the prior commit;
all 411 tests across the touched suites pass after this fix.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit 9ad8693 into main Oct 8, 2026
19 checks passed
@fdaviddpt
fdaviddpt deleted the fix/990 branch October 8, 2026 09:14
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.

check_release_tree.py: two checkers' docstrings claim a follow-up was filed for heredoc-body comment-test ambiguity -- none existed until now

1 participant