-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PEP 634: change walrus pattern to AS pattern #1661
Conversation
Whoops, the PEP 635 half of this conflicts with another branch. I'll remove that for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly good. Just a few fixes to the grammar changes:
@@ -158,7 +158,7 @@ Irrefutable case blocks | |||
|
|||
A pattern is considered irrefutable if we can prove from its syntax | |||
alone that it will always succeed. In particular, capture patterns | |||
and wildcard patterns are irrefutable, as are walrus patterns whose | |||
and wildcard patterns are irrefutable, and so are AS patterns whose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh.
pattern: walrus_pattern | or_pattern | ||
walrus_pattern: capture_pattern ':=' or_pattern | ||
pattern: as_pattern | or_pattern | ||
as_pattern: or_pattern 'as' capture_pattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forget, do we still need/want to unify the grammars in the implementation and spec? As it currently stands, as_pattern
isn't a rule, it's just folded into pattern
:
pattern[expr_ty]:
| value=or_pattern 'as' target=NAME { _Py_MatchAs(value, target->v.Name.id, EXTRA) }
| or_pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this isn't the only difference, though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like the implementation eventually to use the same grammar as the PEP. I'd rather not change the PEP (unless we find bugs) because I use the rule names (e.g. "as pattern") in the text without explanation.
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
No description provided.