Skip to content
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

Merged
merged 3 commits into from
Oct 19, 2020

Conversation

gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Oct 19, 2020

No description provided.

@gvanrossum
Copy link
Member Author

Whoops, the PEP 635 half of this conflicts with another branch. I'll remove that for now.

@gvanrossum gvanrossum changed the title PEP 634, PEP 635: change walrus pattern to AS pattern PEP 634: change walrus pattern to AS pattern Oct 19, 2020
Copy link
Member

@brandtbucher brandtbucher left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh.

pep-0634.rst Outdated Show resolved Hide resolved
pep-0634.rst Outdated Show resolved Hide resolved
pep-0634.rst Outdated Show resolved Hide resolved
pep-0634.rst Outdated Show resolved Hide resolved
Comment on lines -180 to +181
pattern: walrus_pattern | or_pattern
walrus_pattern: capture_pattern ':=' or_pattern
pattern: as_pattern | or_pattern
as_pattern: or_pattern 'as' capture_pattern
Copy link
Member

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

Copy link
Member

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)

Copy link
Member Author

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>
@gvanrossum gvanrossum merged commit dad6766 into master Oct 19, 2020
@gvanrossum gvanrossum deleted the rename-walrus-to-as-pattern branch October 19, 2020 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants