Specialize syntax error for non-`case` statement inside `match` statement
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature or enhancement
Proposal:
Right now using a non-case statement inside a match block gives a rather opaque syntax error:
match a:
case 1:
pass
if 2:
pass
gives:
File "<python-input-0>", line 4
if 2:
^^
SyntaxError: invalid syntax
It's easy to accidentally write something like this when dedenting code too much inside a case block or when not dedenting code enough after the match block.
I propose a specialized syntax error that more clearly points out what the problem is:
SyntaxError: expected 'case' statement inside 'match' statement
PR forthcoming
cc @pablogsal @lysnikolaou
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-146583
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Problem mit der gezeigten match-Anweisung und prüfe den verlinkten PR gh-146583 hinsichtlich der aktuellen Implementierungsrichtung. Erledigt ist die Aufgabe, wenn eine Nicht-case-Anweisung innerhalb eines match-Blocks die vorgeschlagene spezialisierte SyntaxError-Meldung statt des generischen Fehlers wegen ungültiger Syntax erzeugt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 25/100