You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Misleading SyntaxError: cannot use assignment expressions with lambda #137570
IIRC, until today I believed that you could never use an assignment expression in a lambda. I was disabused of this notion only by reading PEP 572 itself. I believe the SyntaxError should ideally read something along the lines of "cannot use unparenthesized assignment expressions with lambda".
I wasn't sure to what category to file this under exactly, sorry if I chose wrong.
Activity
terryjreedy commentedon Aug 9, 2025
I agree that the error message should include 'unparenthesized'.
terryjreedy commentedon Aug 9, 2025
Valid back to at least 3.8, and using the binding, even somewhat sensibly, is possible.
serhiy-storchaka commentedon Aug 9, 2025
It is parsed as
(lambda x: foo) := 2. So, including 'unparenthesized' will not help -- assignment to parenthesized lambda does not work either.Other ambiguous examples, such as
a = b := cora, b := c, raise just "invalid syntax".wyattscarpenter commentedon Aug 9, 2025
@serhiy-storchaka It's the assignment expression that should be described as unparenthesized, not the lambda expression :)