fix(ast_utils): use None sentinel for walk_type_tree seen parameter#165
Open
SoundMatt wants to merge 1 commit into
Open
fix(ast_utils): use None sentinel for walk_type_tree seen parameter#165SoundMatt wants to merge 1 commit into
SoundMatt wants to merge 1 commit into
Conversation
Using a mutable dict as a default argument (`seen={}`) is a classic
Python gotcha: the dict is created once at function-definition time and
shared across all calls. After the first call the dict retains every
visited type name, so a second call would immediately short-circuit on
every node and do nothing.
Replace with the standard `seen=None` sentinel pattern and initialise
`seen = {}` inside the function body.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
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.
walk_type_treedeclaresseen={}as a default argument. Python evaluates default argument values once at function-definition time, so every call that omitsseenshares the same dict object. After the first call the dict already contains all visited type names, meaning every subsequent call skips every node and does nothing.Fix with the standard sentinel pattern:
seen=None, initialised to{}inside the function body.