Repository navigation
Conversation
The name in `case <pattern> as z` was only bound by value and class patterns, via a pending `as_pattern` that the subpattern visitor had to pick up. Sequence and mapping patterns never bound it, so `z` raised UnboundLocalError. Value patterns bound the pattern value instead of the subject, so `case 1.0 as z` gave `z == 1.0` for subject `1` or `True`. Bind the name in visit_as_pattern itself, to the subject, in the block reached when the subpattern matched. This also removes the or-pattern workaround.
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.
compiled
aspatterns in match statements bind the name wrongcase [1, *_] as z: z is the item 1, not the subjectcase 1.0 as z: z is the literal, sof(1)returns 1.0only value and class patterns bound the name, and the value pattern used the literal. now
visit_as_patternbinds the subject after the subpattern matches. this removesbind_as_patternand the workaround invisit_or_pattern