Incorrect SyntaxError location for walrus operator in multi-line conditional expression
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug report
Bug description:
When using the walrus operator (:=) inside a multi-line conditional expression, Python raises a SyntaxError with the error position pointing to the wrong location.
The caret (^) is shown under the expression body instead of the if clause where the syntax issue actually occurs, making debugging misleading.
The error indicator should instead highlight the if portion (or walrus usage context), not the preceding expression line.
Code
(
1
if x := True
else 2
)
Traceback
File "[REDACTED]", line 2
1
^
SyntaxError: expected 'else' after 'if' expression
It locates error to 1 but it should have located to if x := True (line no. 3)
It does not errors when condition is parenthesized:
(
1
if (x := True)
else 2
) # output: 1
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-146305
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 den mehrzeiligen bedingten Ausdruck und seine eingeklammerte Variante auf CPython 3.14 und verfolge anschließend die Behandlung der Parser- oder Syntaxfehlerposition für den Walross-Ausdruck. Als abgeschlossen gilt die Aufgabe, wenn der Cursor auf die Zeile if x := True zeigt, während der eingeklammerte Fall weiterhin korrekt geparst wird und sein Ergebnis meldet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100