Comment by vlade11115
2 days ago
While the article is very entertaining, I'm not a fan of the pattern matching in Python. I wish for some linter rule that can forbid the usage of pattern matching.
2 days ago
While the article is very entertaining, I'm not a fan of the pattern matching in Python. I wish for some linter rule that can forbid the usage of pattern matching.
Can you explain why? Genuinely curious as a lover of case/match. My only complaint is that it is not general enough.
Double indentation
So? Other languages with pattern match similarly have such double indentation. C-style switch with unintended cases is weird.
Should be easily doable with a semgrep rule, e.g.:
...
...
(exits non-0)
You need to make that exclude match = ... since match can also be a variable name. This is because people used to write code like match = re.search(...)
The existing pattern suggested above, "match ...:", will not match 'match = ...'.
Presumably the reason the parent comment suggested semgrep, not just a grep, is because they're aware that naive substring matching would be wrong.
You could use the playground to check your understanding before implying someone is an idiot.
https://semgrep.dev/playground/new
If you're experienced enough with Python to say "I want to eliminate pattern matching from my codebase" you can surely construct that as a pre-commit check, no?