python / python/cpython

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

Offen
#138,864 5 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@sobolevn arbeitet bereits daran.

Seit 13.9.2025.

interpreter-core topic-parser type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.