Repository navigation
python/shell dead_code: count a # comment only when it has a statement's shape (Part of #7207) - #7335
Merged
Merged
Conversation
…ent's shape (Part of #7207) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Contributor
|
No description provided. |
Contributor
This was referenced Oct 31, 2026
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.
Part of #7207 (slice 4, first half). Follows #7322.
commented_keyword_statement(_shared_patterns.py) gains two optional args:marker(a regex replacing//, here#) andextra(one more shape alternative). python and shell now count a keyword-led#comment only when the rest of the line has a statement's shape.(...), an assignment,;{}, a trailing:(# if x > 3:,# try:), orimport a.b [as c]. Prose (# if the user cancels, we retry,# import order matters) no longer counts.;{},(...), an assignment, a quote /$/ pipe / redirect /&, a flag (-rf), a path (/tmp), or; then|do.# echo "debug"counts;# echo is slow heredoes not.test_shell_strict.py: the old positive# echo debugis bare prose-shaped, so it becomes# echo "debug".test_script_dead_code_shape_7207.py: positives and prose negatives per language, plus a long-line ReDoS bound.Known losses (a bare command/statement is indistinguishable from prose): python
# return x,# import a, b; shell# cd build,# ls.Goldens
Re-blessed both legs via
golden-lock.sh crucible_check.py --update --yes. Full-precision fixture moves in commented-logic/dead-code outputs and the fingerprint derived from them (fewer prose hits); zero-dep fixture rewritten, no content diff beyond the same files. Drift is limited to dead_code consumers.Gates
pr_gates --fast9/9 after the import-order fix (lint rerun alone);--ratchets9 pass, 0 skipped. Strict suites for python and shell: pass.Class / Sibling gaps
Class:
dead_coderules matching a bare comment marker + keyword (prose false positives), #7207. Members done across slices: cobol, c/cpp/java, csharp/typescript/javascript/rust, go/kotlin/swift, and now python and shell.Remaining slices (same mechanism,
marker=/extra=): ruby (#;puts "x", baredef Name; dropped here to keep to 5 hand-written files: shared helper, python, shell, new test, shell_strict), perl (#,my|our|sub|...), php (//,#,/*; the//\s*[;{}]andecho|print|$|return|var_dumpalternatives), lua (--,--[[). Each: rule + prose/positive test + golden re-bless.Sibling gaps: the other ~35 languages from the issue's probe list (abap, ada, apex, dart, fortran, groovy, haskell, matlab, rexx, tcl, ...) remain, same mechanism with their own markers.
Lessons for agents
ls ~/.cache/gitgalaxy/ruff-*/bin/ruffmatches several pinned versions; read the pin fromci/requirements/lint.inand useruff-<ver>/bin/ruff. Bareruff checkshows 66 unrelated errors; usepr_gates --fast --only lint.Cross-repo: none.
🤖 Generated with Claude Code