feat(rewrite): introspect container[key] in failure messages - #14815
Draft
RonnyPfannschmidt wants to merge 4 commits into
Draft
feat(rewrite): introspect container[key] in failure messages#14815RonnyPfannschmidt wants to merge 4 commits into
RonnyPfannschmidt wants to merge 4 commits into
Conversation
RonnyPfannschmidt
force-pushed
the
ronny/rewrite-visit-subscript
branch
from
July 31, 2026 19:05
9d4a844 to
dd3a443
Compare
This was referenced Jul 31, 2026
RonnyPfannschmidt
force-pushed
the
ronny/rewrite-visit-subscript
branch
from
July 31, 2026 20:18
dd3a443 to
6a2742b
Compare
This was referenced Jul 31, 2026
RonnyPfannschmidt
force-pushed
the
ronny/rewrite-visit-subscript
branch
from
August 10, 2026 07:21
6a2742b to
ae65813
Compare
RonnyPfannschmidt
force-pushed
the
ronny/rewrite-visit-subscript
branch
from
August 20, 2026 04:35
ae65813 to
34f8cf0
Compare
This was referenced Aug 20, 2026
RonnyPfannschmidt
force-pushed
the
ronny/rewrite-visit-subscript
branch
4 times, most recently
from
August 26, 2026 10:04
ee5f701 to
b3d36ca
Compare
visit_operand() only froze a bare name, so two other unhoisted operands
kept being evaluated after everything that follows them:
assert collect((x := 1), identity(x := 2)) == (1, 2)
assert collect(*items, identity(items := [9])) == (1, [9])
A walrus operator left in place assigns once the enclosing expression is
assembled, which is after the later arguments have run -- so the earlier
argument saw the later assignment. A starred argument hid its value
inside an ast.Starred, where the existing Name check could not see it.
Closes the order-starred-argument group and the remaining
order-call-argument entry in the coverage matrix.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…eeds visit_operand freezes a walrus operand whenever anything follows it, and a comparison always has at least one comparator -- so by the time visit_Compare looks at its left operand, a NamedExpr has already been copied into a temporary. The special case that did it here can never run. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The rewriter only ever visits expressions inside an assert condition, so an attribute always arrives in Load context and the fallback never runs. Removing it keeps the next visitor from copying a guard that cannot fire. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A subscript was opaque: the message showed the value it produced with no indication of which container or key it came from. Decompose it the way attribute access already is. The container goes through visit_operand() because taking the expression away from generic_visit() takes away the hoisting that kept it ordered -- without that, `assert box[identity(box := other)] == 1` would start reading the post-walrus container. The order-axis guard in the coverage matrix fails if this is dropped. Slices keep the generic treatment; decomposing start/stop/step is rarely what a failure message needs. Closes the introspect-subscript group in the coverage matrix. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
RonnyPfannschmidt
force-pushed
the
ronny/rewrite-visit-subscript
branch
from
September 1, 2026 11:54
b3d36ca to
aec8d2d
Compare
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.
Stacked on #14814 → #14447 → #14921 → #14813. Its diff includes theirs.
A subscript was opaque: the message showed the value it produced with no indication of which container or key it came from. Decompose it the way attribute access already is.
Slices keep the generic treatment; decomposing start/stop/step is rarely what a failure message needs.
The container goes through
visit_operand(), because taking the expression away fromgeneric_visittakes away the hoisting that kept it ordered. Without that,assert box[identity(box := other)] == 1would start reading the post-walrus container — a bug this PR would have introduced. Theorder-subscript-containerguard in #14813 fails if the freeze is dropped; I checked by dropping it.This is what the guards in that matrix are for: they are passing tests on
mainprecisely so that a new visitor cannot quietly regress them.Lands the
introspect-subscriptcases of the coverage matrix in #14813, as passing tests (+3).Supersedes part of #14448.