Skip to content

Remove code no control flow can reach, and the check that proves it - #4

Merged
jehrr merged 1 commit into
mainfrom
fix/unreachable-dead-code
Sep 17, 2026
Merged

jehrr merged 1 commit into
mainfrom
fix/unreachable-dead-code

Conversation

@jehrr

@jehrr jehrr commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

playwright_scraper.py carried fifteen lines whose def line had been
lost. What remained -- a docstring and a try: return page.content() --
was indented at function level, so Python attached it to the end of
_mask_credentials, after that function's own return. It parses, it
imports, --help works, compileall passes and this suite was green,
because unreachable code is still valid code. Nothing called it, and
_content_when_settled directly below does the same job.

The same fifteen lines are in six repos of this family, byte for byte,
and have been since each one's first commit -- so this is inheritance
rather than authorship, the shape CLAUDE.md §16 describes.

The check added with it: a statement sitting after a
return/raise/break/continue in the SAME block. Deliberately narrow,
claiming nothing about reachability in general. The undefined-name walk
beside it cannot catch this class, and correctly so -- it pools every
binding in the file rather than tracking scopes, so page used inside
the dead block resolves against the page parameter of a real function
elsewhere in the module. That coarseness is the right trade for what
that check is for, which is why this is a separate check rather than a
tightening of it.

Measured across the eighteen repos of this family: six problems
reported, zero false positives. Verified by control -- appending a
function whose body is return 1 then x = 2 turns the suite red.

Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com

🤖 Generated with Claude Code

playwright_scraper.py carried fifteen lines whose `def` line had been
lost. What remained -- a docstring and a `try: return page.content()` --
was indented at function level, so Python attached it to the end of
_mask_credentials, after that function's own return. It parses, it
imports, --help works, compileall passes and this suite was green,
because unreachable code is still valid code. Nothing called it, and
_content_when_settled directly below does the same job.

The same fifteen lines are in six repos of this family, byte for byte,
and have been since each one's first commit -- so this is inheritance
rather than authorship, the shape CLAUDE.md §16 describes.

The check added with it: a statement sitting after a
return/raise/break/continue in the SAME block. Deliberately narrow,
claiming nothing about reachability in general. The undefined-name walk
beside it cannot catch this class, and correctly so -- it pools every
binding in the file rather than tracking scopes, so `page` used inside
the dead block resolves against the `page` parameter of a real function
elsewhere in the module. That coarseness is the right trade for what
that check is for, which is why this is a separate check rather than a
tightening of it.

Measured across the eighteen repos of this family: six problems
reported, zero false positives. Verified by control -- appending a
function whose body is `return 1` then `x = 2` turns the suite red.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jehrr
jehrr merged commit 9372a17 into main Sep 17, 2026
7 checks passed
@jehrr
jehrr deleted the fix/unreachable-dead-code branch September 17, 2026 08:55
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