-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
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' expressionIt 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: 1CPython versions tested on:
3.14
Operating systems tested on:
Linux
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error