Files
codeql/python/extractor/tests/parser/soft_keywords_new.py
Taus e04821e9e3 Python: Allow use of match as an identifier
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.
2025-06-26 15:33:00 +00:00

21 lines
334 B
Python

match[1]
match[2] = 3
match.foo = 4
match()
match[5] : case
# match used "properly"
match [6]:
case 7:
pass
print >> 8, "hello" # Python 2-style print
pront >> 9, "world" # How this would be interpreted in Python 3
await [10] # In Python 2 this would be an indexing operation, but it's more likely to be an await.