Open fcheung opened 11 months ago
Thank you for your contribution @fcheung 🙇🏼♂️ match
and case
are a bit special in Python. They are called soft keywords. So in the use case highlighted above, they are keywords but not for other, e.g. as variables.
# Keywords
match point:
case Point(x, y) if x == y:
print(f"The point is located on the diagonal Y=X at {x}.")
case Point(x, y):
print(f"Point is not on the diagonal.")
# Non-keywords
case = 1
match = 1
match if True else bar
We can port these behaviours from Pygments (see related PR).
This adds match & case as keywords, used by python 3.10 structural pattern matching ( https://peps.python.org/pep-0634/ )
(screenshot from rouge's visual test page)