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

Open
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.
@tausbn tausbn marked this pull request as ready for review June 27, 2025 11:53
@Copilot Copilot AI review requested due to automatic review settings June 27, 2025 11:53
@tausbn tausbn requested a review from a team as a code owner June 27, 2025 11:54
@tausbn tausbn requested a review from IdrissRio June 27, 2025 11:54
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

@IdrissRio IdrissRio left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Quick (non-blocking) question: would it make sense to run DCA to check that none of the existing projects fail due to some subtle corner case?
I guess that if anything unexpected happens, it would still be caught in the nightly run.

@tausbn
Copy link
Contributor Author

tausbn commented Jun 27, 2025

Quick (non-blocking) question: would it make sense to run DCA to check that none of the existing projects fail due to some subtle corner case? I guess that if anything unexpected happens, it would still be caught in the nightly run.

Oh yes, I completely forgot to do that. We usually do that for any change, no matter how small (unless it literally doesn't touch any code at all), so thanks for the reminder!

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.

2 participants