Changing match and case to keywords

Hi coders;

As you may know, match-case statements are an easy way to run stuff in a clean and orderly way.

But why are they not highlighted in a special color like normal keywords are? In fact, they are the only soft keywords Python has.

My proposal is that they are made into the keywords that are highlighted like others and that soft keywords are removed entirely; so that new Python learners are not confused by ‘match’ and ‘case’ not being highlighted.

Thank you.

(And if it turns out soft keywords ARE necessary in Python, I will take my words back.)

If they became real keywords, then existing code that uses them as identifiers would break. That’s not acceptable, and it’s why they were made soft keywords in the first place.

Syntax highlighting is a different issue. Maybe it’s possible to highlight them when they’re acting as keywords.

I (partially) understand the reply you gave, but can you elaborate on the difference between keywords and identifiers?

match=True is using it as an identifier, which is valid code.

oh now i get it. thank you

Even re.match from the standard library would become invalid.

This is a question for your syntax highlighter. Here’s Python’s own REPL:

It’s able to recognize when match and case are being used as names, and when they’re being used as keywords, and colorizes them accordingly. I’d say this is something to file as a bug report for your editor/environment rather than change the language.

match and case are not the only soft keywords. _ may also be one in a case statement. lazy now is too. IDLE also matches them when appropriate except in a few rare cases.

type is also a soft keyword now, iirc?

Yes. And that’s all of them, for 3.15:

>>> import keyword
>>> keyword.softkwlist
['_', 'case', 'lazy', 'match', 'type']

Thank you for your information.