Repository navigation
fix(python): no probe on lines in the body of if TYPE_CHECKING: (#14156) - #14455
Conversation
…ction (#14097) A new function, method or arrow whose signature a formatter wrapped over several lines got one finding per physical signature line: the opening line, each parameter line (read as field_construction) and the `): T {` closer (read as predicate). The one-line spelling of the same signature already yields no header probe, so the result depended on line width. Read the header as one unit: from the owner's first line to the first line ending in `{` outside the parameter list, accepted only when the joined text passes is_signature_opening_line. A default value, a destructuring default, a parameter property, a computed key or a decorator keeps every line probed, as do a constructor, a changed signature of an existing owner, a header that is not all added lines, and a body with no added probe line. On 100 real commits of zod, hono, date-fns, axios and TanStack query this removes 397 signature-line findings (380 date-fns, 17 hono). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016EQRVmHPS5rKE967z5W6be
…des a body line (#14097) The wrapped-header reader counts round brackets only to pick the line where the parse is tried. Pin the consequence of a miscount: an unclosed `(` in a header comment costs a missed header (its lines keep their probes), a body comment that rebalances the count does not make a body line part of the header, a stray `)` still reads the real header, and a `)` inside a default string keeps the header probed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016EQRVmHPS5rKE967z5W6be
…4156) The body of `if TYPE_CHECKING:` (or `if typing.TYPE_CHECKING:`) never runs, so an import or alias edited, added or deleted there changes no behavior. The Python preview probed each such line. `type_checking_block.rs` reads the block ranges from the parsed module and returns nothing when the flag's binding is not the one from `typing`/`typing_extensions` (or the `TYPE_CHECKING = False` idiom). The ranges feed the existing no-behavior decision on both sides of the diff, so runtime code moved into such a block keeps its probe, and the `else` branch is never included. Found on real commits of requests, click, httpx and rich: 20 findings on 9 commits gone, none added, across 120 Python commits. Closes #14156 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016EQRVmHPS5rKE967z5W6be
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 15 minutes. View limit details
Pre-merge checks:
|
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
ripr static exposure checkCommit Took 292s. |
) Review repairs from Devin on #14455: - An added line in a block counts as quiet for its run only when the line it replaced did not run either. Runtime code moved into a block beside a runtime edit now keeps its probe. - A write or `del` of a `TYPE_CHECKING` attribute (for example `typing.TYPE_CHECKING = True`) or of the bare name marks the file unread. - A workspace with its own top-level `typing` or `typing_extensions` module (at the root or under `src/`) reads no block, since an import may resolve there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016EQRVmHPS5rKE967z5W6be
|
Answers to the four Devin findings on
Generated by Claude Code |
EffortlessSteven
left a comment
There was a problem hiding this comment.
SOURCE_REVIEW_READY
Source review of head fcc5b01d4883b72ed9f7e26f849cb774805a9a50 (basis main bc82bf22; the diff against main is this fix only: 6 files).
Read in full: type_checking_block.rs, type_checking_block_tests.rs, the python.rs wiring (new and old ranges, the shadowed-typing gate, the quiet-run closure, the two context fields, OldSideRanges), the no-op test in classify.rs, is_removed_behavior_line in deleted_lines.rs, and the changelog fragment.
Checked:
- Flag recognition reads the flag as false only when nothing in the file can make it true. The bare name counts only after
from typing import TYPE_CHECKING,from typing_extensions import TYPE_CHECKINGorTYPE_CHECKING = False. Any other binding of the name (assignment,del, parameter,global, loop target,except ... as, def or class name), any write to aTYPE_CHECKINGattribute such astyping.TYPE_CHECKING = True, a star import from another module, or amatchstatement marks the file unread. The attribute form needsimport typingorimport typing_extensionsunder a name nothing else rebinds. - A workspace with its own top-level
typingortyping_extensionsmodule, at the root or undersrc/, reads no block at all. - Range shape: the block body, plus the
ifline only when the test ends on that line. A body on theifline itself is never counted;elifandelseare walked as ordinary code;if not TYPE_CHECKING:and compound tests are not the flag test. - Both sides of the diff: an added block line counts as quiet for its run only when its paired old line was also non-running, and the classifier drops a change only when both sides are type-checking-only or non-behavioral. Runtime code moved into a block keeps its probe, alone or beside a runtime edit. A deleted line from an old block is not a removed behavior line.
- Tests: 9, all but the two table tests through
PythonAdapter::analyze_diffon a fixture with a runtime caller and a test. Removal experiments: forcing the block ranges empty turns 4 tests red; dropping the paired-line condition and the shadowed-typing gate turnsruntime_code_moved_into_a_block_beside_a_runtime_edit_keeps_probeandworkspace_typing_module_keeps_block_probesred. - The four Devin findings on
3ea9df9a: three repaired infcc5b01dwith the tests above; the spec-mapping one answered in the conversation. All four threads are resolved. CodeRabbit and Gemini returned quota notices, so there is no review from them. - Real commits: 20 findings gone on 9 commits of requests, httpx, rich and click, each checked to sit in such a block; none added.
Local proof on this head: cargo test -p ripr --lib python:: 2,091 passed, 1 ignored; cargo xtask precommit pass (digest sha256:2830fad4...).
Static evidence only; Python stays preview. Hosted qualification on this exact head is next.
Generated by Claude Code
|
Generated by Claude Code |
EffortlessSteven
left a comment
There was a problem hiding this comment.
REVIEW_READY
Final pass on head fcc5b01d4883b72ed9f7e26f849cb774805a9a50 (basis main bc82bf22). The source review recorded on this same head at 03:58Z stands; the diff has not changed since.
Hosted evidence on this exact head:
Admit PR Candidate: success.- Rust tests shards 1 to 4 of 4 and
Rust test shards verify: success. Ripr Rust Small Result: success (05:32Z).Ripr Windows Gate Result: success.cargo-deny(Security workflow, not a required check) is red on RUSTSEC-2026-0486 forrustix 1.1.5, which comes from main's lock file; the bump is #14240. Explained in the conversation.
Review inputs: Devin's four findings on 3ea9df9a (three repaired with tests, one answered), all threads resolved; CodeRabbit and Gemini returned quota notices, so there is no review from them; the ripr comment on this diff is advisory static evidence.
Claim boundary unchanged: changed lines in the body of a recognised if TYPE_CHECKING: block yield no probe in the Python preview, and every case where the flag could be true keeps its probes. Static evidence only.
Generated by Claude Code
EffortlessSteven
left a comment
There was a problem hiding this comment.
VERDICT: BLOCK fcc5b01 — the recognizer misses a walrus rebind of the flag, so a block that runs at runtime is treated as type-checking-only and its changed lines are dropped.
Blocking finding: a walrus rebind is not read
type_checking_block.rs claims a closed recognizer ("no statement in the file may bind either name any other way"), and the PR's Claim Boundary says "A file that rebinds or patches TYPE_CHECKING ... is read as before." Bindings::read_statement has no arm for Stmt::Expr and does not read the test expression of Stmt::If/Stmt::While, so a named-expression target is never seen:
from typing import TYPE_CHECKING
(TYPE_CHECKING := True)
if TYPE_CHECKING:
import aBindings records flag_is_typing = true from the import, never sees the walrus, and collect records lines 3-4 as type-checking-only. At runtime the walrus sets the flag true, so import a runs; a diff that edits that import is dropped as a no-op. The same holds for if (TYPE_CHECKING := True): followed by a later if TYPE_CHECKING:.
The repository already walks Expr::NamedExpr targets in source_facts.rs (collect_assignment_target_facts), so the fix is to walk expression trees for NamedExpr targets (and the tests of if/while/assert) and mark the file unreadable when the target is the flag or a typing alias, or to add a Stmt::Expr/test-expression walk. A test with the input above would pin it.
Non-blocking: the "moved" regression test does not exercise its named case
runtime_code_moved_into_a_block_beside_a_runtime_edit_keeps_probe adds lines 10-14 and removes lines 10 and 14. The harness takes each added line's text from PRICING_PY, so added line 10 is the alias line, not DISCOUNT = compute_discount(); the removed line 10 is also a block line. reconstruct_old_source returns None (the removed line 14 index is past the end after five added lines are removed), so old_type_checking_ranges is empty and the old line is treated as behavioral. The test is green because the old source is unavailable, not because the counterpart rule handled a runtime line moved into the block. The claim is covered by runtime_code_replaced_by_a_type_checking_line_keeps_probe (old runtime line, new block line, old source reconstructed), so this is a test-quality defect, not a second production defect. The assertion is also contains(&10) rather than an exact set.
Qualification the head still lacks
The current PR body has no Source review: REVIEW_READY fcc5b01d... line (the last "Admit PR Candidate" run finished at 05:32, before the body's 19:45 edit). A fresh admission run reads the body and would refuse; the review at this head is SOURCE_REVIEW_READY/REVIEW_READY, not the machine-readable body line.
What I checked
Read the full diff at fcc5b01: the new recognizer, the python.rs quiet-run and classifier wiring, deleted_lines.rs, and the nine tests. Checked the binding walker against Stmt variants and the repo's NamedExpr handling in source_facts.rs. No build, test, or mutation run; no checkout.
A named expression can rebind the flag or a typing module alias from any expression (`(TYPE_CHECKING := True)`, an `if` test, a call argument). The statement walk never saw those targets, so the block was still read as type-checking-only. The token stream now finds every `name :=` whose name is the flag or a typing alias, and such a file reads no block. The moved-line test now uses a fixture whose old side reconstructs and whose moved line shares an added run with a runtime edit, so it fails without the paired-line condition, and it asserts the exact probe set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016EQRVmHPS5rKE967z5W6be
|
Answer to the source review of
Proof on Generated by Claude Code |
EffortlessSteven
left a comment
There was a problem hiding this comment.
SOURCE_REVIEW_READY
Inspected on head 12dd7b64f2d32b4dcfd56355125179d15532ec11 (diff fcc5b01d..12dd7b64, plus the full PR diff against main):
type_checking_block.rs:rebinds_by_named_expressionlexes the parsed file and refuses anyname :=whose name isTYPE_CHECKINGor a recorded typing alias; a lexer error also refuses. It runs after the statement walk, so the typing aliases it checks are the complete set. A:=target is always a bare name, so no expression position is missed.- Tests: four new negative shape rows (statement,
iftest, comment between target and:=, rebound alias). The moved-line test now reconstructs its old side, asserts old and new block ranges, and asserts the exact probe set[5, 6]. - Removal experiments: the
:=check off turns the shape table red; the paired-line condition off turns the moved-line test red. - Proof: focused 9 pass, Python adapter suite 2,091 pass (1 ignored),
cargo xtask precommitpass.
Hosted qualification for this head is still to run.
Generated by Claude Code
EffortlessSteven
left a comment
There was a problem hiding this comment.
SOURCE_REVIEW_READY
VERDICT: APPROVE 12dd7b6 — no blocking findings on this head.
The walrus blocker from my review at fcc5b01 is repaired. rebinds_by_named_expression lexes the file and treats any NAME := whose name is the flag or a typing-module alias as an unreadable binding, so type_checking_only_line_ranges returns no ranges and every line keeps its probe. The scan errs only toward keeping probes: a lexer error counts as rebinding, and a walrus in a nested scope costs suppression but never causes a wrong one. The lexer is built without full-lexer, so comments and non-logical newlines are dropped and a target split from := by a comment stays adjacent; the new shapes rows cover statement-level, in-test, comment-split and typing-alias walruses, and the rewritten moved-line test drives reconstruct_old_source and asserts the exact probed set [5, 6]. All four review threads are resolved.
Qualification still missing on this head: the Rust gates (Ripr Rust Small on GitHub Hosted / Rust gates and the four test shards) are pending; the queue must run them before landing.
EffortlessSteven
left a comment
There was a problem hiding this comment.
REVIEW_READY
Final pass on head 12dd7b64f2d32b4dcfd56355125179d15532ec11 (basis main bc82bf22). The source review on this head stands, and the second reviewer's pass on this head found nothing blocking.
Hosted evidence on this exact head: merge-ready run 43310998718 has Rust gates, all four test shards, the shard verify, and Ripr Rust Small Result all passing. The earlier run 43305911865 was cancelled when this one started, so its Result does not apply. All four review threads are resolved. CodeRabbit returned only quota and skip notices, so it gave no review.
Generated by Claude Code
EffortlessSteven
left a comment
There was a problem hiding this comment.
VERDICT: APPROVE 12dd7b6 — no blocking findings on this head.
Refresh of my BLOCK at fcc5b01d. The blocking finding is repaired at this head.
The walrus rebind is now read. rebinds_by_named_expression (type_checking_block.rs:59) lexes the source and returns unreadable when a := follows a name that is the flag or a typing-module alias. That covers the exact input I named ((TYPE_CHECKING := True) before if TYPE_CHECKING:), a walrus in the if test itself, a target split from := by a comment inside brackets, and a walrus on import typing as t. The four new cases in type_checking_block_shapes pin each one. A lexer rejection also counts as unreadable, so the scan fails closed.
The test-quality defect is repaired. runtime_code_moved_into_a_block_beside_a_runtime_edit_keeps_probe now uses MOVED_PY, reconstructs the old source, asserts the old block is 3..=4 and the new block is 3..=5, and asserts the exact probe set [5, 6]. The moved line is now genuinely a runtime line moved into the block beside a behavioral edit, not a case that passed because the old source was unavailable.
Qualification. The PR body carries Source review: SOURCE_REVIEW_READY 12dd7b64..., and the latest routed run is green: Rust gates, all four test shards, shard verify, and Ripr Rust Small Result are SUCCESS. All four review threads are resolved.
Could not check: no local build, test, or mutation run; the analysis is static. No checkout, branch, or worktree was created.
EffortlessSteven
left a comment
There was a problem hiding this comment.
REVIEW_READY
Final pass on head 12dd7b64f2d32b4dcfd56355125179d15532ec11, restated so it is the latest review on this head. The second reviewer's 22:31Z pass on this head approves it.
Hosted evidence is unchanged: merge-ready run 43310998718 passed (Rust gates, four test shards, shard verify, Ripr Rust Small Result), and all four review threads are resolved.
Generated by Claude Code
EffortlessSteven
left a comment
There was a problem hiding this comment.
SOURCE_REVIEW_READY
VERDICT: APPROVE 12dd7b6
Reviewed head: 12dd7b6
Refresh of my BLOCK at fcc5b01d. The blocking finding is repaired at this head.
The walrus rebind is now read. rebinds_by_named_expression (type_checking_block.rs:59) lexes the source and returns unreadable when a := follows a name that is the flag or a typing-module alias. That covers the exact input I named ((TYPE_CHECKING := True) before if TYPE_CHECKING:), a walrus in the if test itself, a target split from := by a comment inside brackets, and a walrus on import typing as t. The four new cases in type_checking_block_shapes pin each one. A lexer rejection also counts as unreadable, so the scan fails closed.
The test-quality defect is repaired. runtime_code_moved_into_a_block_beside_a_runtime_edit_keeps_probe now uses MOVED_PY, reconstructs the old source, asserts the old block is 3..=4 and the new block is 3..=5, and asserts the exact probe set [5, 6]. The moved line is now genuinely a runtime line moved into the block beside a behavioral edit, not a case that passed because the old source was unavailable.
Qualification. The PR body carries the machine-readable source-review line for this head, and the latest routed run is green: Rust gates, all four test shards, shard verify, and Ripr Rust Small Result are SUCCESS. All four review threads are resolved.
Could not check: no local build, test, or mutation run; the analysis is static. No checkout, branch, or worktree was created.
|
Verification on current live head
Focused proof on that exact head: No label, queue, or merge action was taken. Temporary worktree and Cargo target were removed after verification. |
Requested by Steven Zimmerman · project thread
Summary
if TYPE_CHECKING:. That body never runs, so an import or type alias edited, added or deleted there changes no behavior.type_checking_block.rsreads the block ranges from the parsed module and feeds them into the existing no-behavior decision on both sides of the diff.ripr checkon real commits of well-known Python projects (read-only clones). On 120 commits of requests, flask, click, attrs, httpx and rich, 20 findings on 9 commits are gone, every one inside such a block, and none are added. requests5691f59went from 8 findings to 1.Closes #14156
Source review: SOURCE_REVIEW_READY 12dd7b6
Swarm / Source Boundary
dependency, or repo-ops development for
ripr-swarmSource-of-truth Links
Proposal: n/a
Spec: n/a
ADR: n/a
Plan item: n/a
Governing issue or accepted claim: #14156
Acceptance delta (one sentence): a changed line in the body of a recognised
if TYPE_CHECKING:block yields no probe, and runtime code moved into one, theelsebranch, and a rebound flag keep their probes.Candidate Relationships
Candidate branch (GitHub PR head is authoritative after publication):
claude/project-thread-w844qlStack parent or prerequisite PR (if any): none (the branch carries a merge of main after #14153; the diff against main is this fix only)
Proposed replacement of PR (if any; not yet accepted): none
Acceptance retained from a replaced candidate (if any): none
Accepted winner and losing candidate disposition (when decided): n/a
Scope
python/type_checking_block.rs(new):type_checking_only_line_ranges. The flag must be bound byfrom typing import TYPE_CHECKING,from typing_extensions import TYPE_CHECKINGorTYPE_CHECKING = False;typing.TYPE_CHECKINGneedsimport typing [as x]. Any other binding of the name (a statement or a:=target), a star import from another module, or amatchstatement makes the file unreadable and returns no ranges. The range is the block body, plus theifline when the test is on one line; a body on theifline itself and theelsebranch are never included.python.rs: ranges for the new and old file; new lines in a block join the quiet-line run and the classifier context.python/classify.rs:new_line_type_checking_only/old_line_type_checking_onlyjoin the docstring flags in the no-op test, so a change is dropped only when both sides are type-checking-only or non-behavioral.python/deleted_lines.rs: a deleted line from such a block is not a removed behavior line.python/type_checking_block_tests.rs(new): 9 tests, 7 throughPythonAdapter::analyze_diff.fcc5b01d, from Devin): an added block line is quiet for its run only when its paired old line also did not run; a write ordelof aTYPE_CHECKINGattribute or name marks the file unread; a workspace with its own top-leveltyping/typing_extensionsmodule reads no block.12dd7b64, from the source review offcc5b01d): a named expression whose target is the flag or a typing alias ((TYPE_CHECKING := True),if (t := load()):) marks the file unread; it is found in the token stream, so every expression position is covered. The moved-line test now uses a fixture whose old side reconstructs and asserts the exact probe set.changelog.d/python-type-checking-block-14156.md.Scope Classification
Production delta:
if TYPE_CHECKING:block.Evidence/support delta:
Single acceptance criterion:
if TYPE_CHECKING:yields no finding, while runtime lines beside it keep theirs.Non-goals:
if False:,if 0:),typing.TYPE_CHECKINGreached through other import shapes, theelsebranch, TypeScriptimport type.Support-tier Impact
Claim/proof notes:
preview.Policy Impact
Ledger or exception notes:
Proof
Result, failures, or skipped proof:
12dd7b64.12dd7b64: disabling the:=check turnstype_checking_block_shapesred; dropping the paired-line condition inpython.rsturnsruntime_code_moved_into_a_block_beside_a_runtime_edit_keeps_probered (it asserts the reconstructed old side and the probe set[5, 6]).fcc5b01d):workspace_typing_module_keeps_block_probesgoes red.python.rsforced empty): 4 tests go red (edited_alias_in_a_type_checking_block_is_not_probed,added_type_checking_block_is_not_probed,line_deleted_from_a_type_checking_block_is_not_probed,runtime_line_beside_a_type_checking_edit_keeps_its_probe); the replaced-runtime control and the shape table stay green, as they should on both sides.if TYPE_CHECKING:/if typing.TYPE_CHECKING:/if t.TYPE_CHECKING:block (httpx1805ee0,2ea2286; requests3816cfa,5691f59,84d10f0,e50e594,e511bc7; richb502fbd; click22177f8).cargo xtask precommit: pass on8ab2a301,fcc5b01dand12dd7b64. A first run failedcheck-local-contexton a fixture string that read as a Windows path (\nclass C:\n); the fixture class was renamed.merge-ready.Continuation record
Claim Boundary
if TYPE_CHECKING:block no longer produce findings in the Python preview.TYPE_CHECKING(including by:=), imports it from elsewhere, or usesmatchis read as before.Rollback
Spec-Test-Code Traceability
crates/ripr/src/analysis/language/python/type_checking_block_tests.rscrates/ripr/src/analysis/language/python/type_checking_block.rs,python.rs,python/classify.rs,python/deleted_lines.rsStatic Language Check
killed,survived,untested,proven, andadequate.CI Economics
n/a
Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.panic,unwrap,expect,todo, orunimplementedin tests.Gates
cargo fmt --checkcargo xtask precommit(see Proof for the heads)🤖 Generated with Claude Code
https://claude.ai/code/session_016EQRVmHPS5rKE967z5W6be