Title: Improve SyntaxError message for `match` · Issue #151128 · python/cpython · GitHub
Open Graph Title: Improve SyntaxError message for `match` · Issue #151128 · python/cpython
X Title: Improve SyntaxError message for `match` · Issue #151128 · python/cpython
Description: 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 tha...
Open Graph Description: 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 lan...
X Description: 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 program...
Opengraph URL: https://github.com/python/cpython/issues/151128
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improve SyntaxError message for `match`","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nCurrently, Python raises:\n\n```python\nSyntaxError: invalid syntax. Did you mean 'with'?\n```\nfor `switch foo:`. \n\nThis 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.\n\nThus, users typing switch almost certainly intended to use match, mistakenly substituting the keyword from other languages, rather than meaning to write a with statement.\n\nTherefore, I believe it’s better to raise:\n```python\nSyntaxError: invalid syntax. Did you mean 'match'?\n```\nin this case.\n\nAdditionally, code with typos like mach foo: or matc foo: currently lacks a keyword typo suggestion.\n\n### Has this already been discussed elsewhere?\n\nI have already discussed this feature proposal on Discourse\n\n### Links to previous discussion of this feature:\n\nhttps://discuss.python.org/t/improve-syntaxerror-message-for-match/107684\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-151129\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/IvyXu420","@type":"Person","name":"IvyXu420"},"datePublished":"2026-06-09T06:41:11Z","url":"https://github.com/python/cpython/issues/151128"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:efdcb0ff-932c-0f98-8f7a-299d4ae36c15 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D588:1F68:1530FB0:1C35DB1:6B021F06 |
| html-safe-nonce | 7440376bab2afb49301994dbfaf805a3f470de906f5c74f5fee15479710d3d3d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENTg4OjFGNjg6MTUzMEZCMDoxQzM1REIxOjZCMDIxRjA2IiwidmlzaXRvcl9pZCI6Ijg1ODY3NDEzOTcyNzk4NzQ4MjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6d0012661d0abbd626a83a2dfd19ba77674e5618bac9d2b1bf55d025bf2b25c1 |
| hovercard-subject-tag | issue:4619534642 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/151128/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1ebff151505d8c8bc3da623ea1f064028f793ed5a562f2783df4bfc8d09d865f/python/cpython/issues/151128 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1ebff151505d8c8bc3da623ea1f064028f793ed5a562f2783df4bfc8d09d865f/python/cpython/issues/151128 |
| og:image:alt | 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 lan... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | IvyXu420 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width