The filedef file filetypes.python.in is missing the keywords "match" and "case".
`match` and `case` are soft keywords, they are only keywords in certain parsing contexts, in all other cases they are plain identifiers.
If added to the filedef keyword list _all_ cases will be highlighted as keywords.
Unfortunately because they depend on parsing context `match` and `case` are not recognised as anything other than identifiers by the Python lexer which only recognises syntactic entities and does not recognise sufficient context.
The same issue exists for C++ which also has contextual keywords. In the C++ case identifiers like `final` or `override` are in the list of keywords, so perhaps it will be ok for Python, opinions by Python experts?
I don't think there will be many programmers who will want to use keywords as identifiers, even when they can. So my vote would be to add them to the keywords list since for most people it will make the most sense.
I agree. Would you be able to make a PR?
From my experience this would help to not accidentally use a keyword as variable (even if the interpreter would allow) because the variable has a special color in contrast to other variables.
Yeah new code won't use it, but it will break the display of existing code that innocently used `match` and `case`.
And its not just variables, IIUC the lexer does not distinguish function calls from other identifiers. That means the fact that `match` is a method in the Python standard `re` and `pathlib` libraries means all those uses will be shown as keywords as well. And those are not user code and are not likely to change.
I tend to agree with @nixuser58 and @kugel-.
With proper highlighting of the new keywords, the code looks much better. The drawback is the mentioned "re.match" function which is now also highlighted. After all, for me the better highlighting of the case-match pattern wins.
See #3277 for an implementation and also screenshots.
Closed #3263 as completed via #3277.
github-comments@lists.geany.org