This is confusing and irrelevant, because in many other programming languages, switch is a reserved keyword that serves almost the same function as Python’s match.
Thus, users typing switch almost certainly intended to use match, mistakenly substituting the keyword from other languages, rather than meaning to write a with statement.
Therefore, I believe it’s better to raise:
SyntaxError: invalidsyntax. Didyoumean'match'?
in this case.
Additionally, code with typos like mach foo: or matc foo: currently lacks a keyword typo suggestion.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Activity
zang-langyan commented on Jun 9, 2026
#151129 take a look out this pr, it should do the trick
serhiy-storchaka commented on Jun 9, 2026
See also #146406 as a precedence.
gh-151128: Improve SyntaxError message for cross language keywords (G…
pythongh-151128: Improve SyntaxError message for cross language keywo…