python / python/cpython

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

Aperta
#138,864 5 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@sobolevn ci sta già lavorando.

Dal 13/9/2025.

interpreter-core topic-parser type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.