python / python/cpython

`case ...:` generates unclear `SyntaxError` message

Open
#138,864 5 comments 0 reactions 1 assignee View on GitHub

@sobolevn is already working on this.

Since Sep 13, 2025.

interpreter-core topic-parser type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

I've noticed that this simple python code sample generates unclear error message:

>>> match 1:
...    case ...: ...
  File "<stdin>", line 2
    case ...: ...
         ^^^
SyntaxError: invalid syntax

I propose making the error message clearer:

>>> match 1:
...    case ...: ...
  File "<stdin>", line 2
    case ...: ...
         ^^^
SyntaxError: cannot use case statement with ellipsis

We already have this logic for := expressions:

>>> (a[0] := 1)
  File "<stdin>", line 1
    (a[0] := 1)
     ^^^^
SyntaxError: cannot use assignment expressions with subscript

Since case requires some special grammar (not regular python expression) it would be user-friendly to improve this message.

I have a PR ready.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-138865

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.