Conversation
`Analyzer.matches` yields a top-level match as soon as it is found and
attaches that match's children as the analysis continues. `sbud` bound the
generator and drained it inside the comprehension that builds `struc`, so
`to_obj` ran on each top-level match before its children existed.
The result was a correctly shaped object holding one element where the
same file yields fifty-five, and nothing in the signature or the docstring
said so. The command line was unaffected because `__main__` materializes
the matches first.
one-member ZIP, sbud() 1 node
one-member ZIP, sbud(matches=list(...)) 55 nodes
A supplied iterable is now materialized too, not just the default: a
caller passing a generator has no way to know how far this needs it
drained, and before this it got the same truncated tree.
Closes #3584.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RG45aqyyCLkL5b1UB5GWd7
This branch has not been deployed
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.
Closes #3584.
Analyzer.matchesyields a top-level match as soon as it is found and attaches that match's children as the analysis continues.sbudbound the generator and drained it inside the comprehension that buildsstruc, soto_objran on each top-level match before its children existed.The object is correctly shaped and almost entirely empty. Nothing in the signature or the docstring warned about it, which is the part #3577 is about: the method returns successfully with the wrong contents. The command line was unaffected, because
__main__materializes the matches before calling this.The change
matches = list(self.matches() if matches is None else matches).A supplied iterable is materialized too, not only the default. A caller passing a generator cannot know how far
sbudneeds it drained, and before this it got the same truncated tree — the issue does not mention that shape, but it was broken in exactly the same way:The docstring now says
matchesis an optimization for a caller that already has them, never a precondition.Tests
tests/test_analyzer.pyasserts whole-object equality across all three call shapes, which is the property the issue asks for and the version that cannot rot as the tree changes. Two guards around it:test_the_tree_is_not_trivially_small, because whole-object equality passes happily if every caller gets the same truncated tree.test_sbud_can_be_called_twice, sinceAnalyzer.matchescaches intomatches_so_farand a second call has to agree with the first. It did not before this change.All three fail with the change reverted. Full suite: 387 passed, 1,511 subtests. Blocking flake8: 0.
🤖 Generated with Claude Code