Describe the bug
Incorrect error message for an invalid usage of the walrus operator in a nested comprehension.
Code or Screenshots
If possible, provide a minimal, self-contained code sample (surrounded by triple back ticks) to demonstrate the issue. The code should define or import all referenced symbols.
print([
f"{i=}"
for i in [
x
for j in range(10)
if (x := j * 2) % 3 == 0
]
])
Pylance gives:
Operator ":=" is not allowed in this context without surrounding parentheses
Note the expression is already surrounded by parentheses.
Whereas running the code gives:
SyntaxError: assignment expression cannot be used in a comprehension iterable expression
VS Code extension or command-line
VS Code:
Client: Pylance client (2026.2.1) started with python extension (2026.4.0)
Pylance language server 2026.2.1 (pyright version 1.1.408, commit 138238b4)
Describe the bug
Incorrect error message for an invalid usage of the walrus operator in a nested comprehension.
Code or Screenshots
If possible, provide a minimal, self-contained code sample (surrounded by triple back ticks) to demonstrate the issue. The code should define or import all referenced symbols.
Pylance gives:
Note the expression is already surrounded by parentheses.
Whereas running the code gives:
VS Code extension or command-line
VS Code: