Skip to content

Improve SyntaxError message for match #151128

@ByteFlowing1337

Description

@ByteFlowing1337

Feature or enhancement

Proposal:

Currently, Python raises:

SyntaxError: invalid syntax. Did you mean 'with'?

for switch foo:.

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: invalid syntax. Did you mean '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

Links to previous discussion of this feature:

https://discuss.python.org/t/improve-syntaxerror-message-for-match/107684

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions