Skip to content

gh-146260: Improve syntax error for assignment expression inside conditional expression#146305

Open
brianschubert wants to merge 1 commit intopython:mainfrom
brianschubert:gh-146260-syntax-err-walrus-in-ternary
Open

gh-146260: Improve syntax error for assignment expression inside conditional expression#146305
brianschubert wants to merge 1 commit intopython:mainfrom
brianschubert:gh-146260-syntax-err-walrus-in-ternary

Conversation

@brianschubert
Copy link
Contributor

@brianschubert brianschubert commented Mar 22, 2026

Demo:

>>> (
...     1
...     if x := True
...     else 2
... )
... 
  File "<python-input-0>", line 3
    if x := True
       ^^^^^^^^^
SyntaxError: assignment expression must be parenthesized inside conditional expression

>>> (
...     1
...     if (x := True)
...     else 2
... )
1

@brianschubert
Copy link
Contributor Author

See Guido's comment in the issue about relaxing the syntax instead: #146260 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant