Skip to content

Python: Allow use of match as an identifier #19895

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tausbn
Copy link
Contributor

@tausbn tausbn commented Jun 26, 2025

This previously only worked in certain circumstances. In particular, assignments such as match[1] = ... or even just match[1] would fail to parse correctly.

Fixing this turned out to be less trivial than anticipated. Consider the fact that

match [1]: case (...)

can either look the start of a match statement, or it could be a type ascription, ascribing the value of case(...) (a call) to the item at index 1 of match.

To fix this, then, we give match the identifier and match the statement the same precendence in the grammar, and additionally also mark a conflict between match_statement and primary_expression. This causes the conflict to be resolved dynamically, and seems to do the right thing in all cases.

This previously only worked in certain circumstances. In particular,
assignments such as `match[1] = ...` or even just `match[1]` would fail
to parse correctly.

Fixing this turned out to be less trivial than anticipated. Consider the
fact that
```
match [1]: case (...)
```
can either look the start of a `match` statement, or it could be a type
ascription, ascribing the value of `case(...)` (a call) to the item at
index 1 of `match`.

To fix this, then, we give `match` the identifier and `match` the
statement the same precendence in the grammar, and additionally also
mark a conflict between `match_statement` and `primary_expression`. This
causes the conflict to be resolved dynamically, and seems to do the
right thing in all cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant