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
Bug report
Bug description:
When using the walrus operator (
:=) inside a multi-line conditional expression, Python raises aSyntaxErrorwith 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
ifportion (or walrus usage context), not the preceding expression line.Code
( 1 if x := True else 2 )Traceback
It locates error to
1but it should have located toif 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
Linked PRs