-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Specialize syntax error for assignment expressions in invalid places #146601
Copy link
Copy link
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-parsertype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
There are a few places where (unparenthesized) assignment expressions are not accepted but users might think of using them. For example:
>>> func(arg=x := foo())
File "<python-input-0>", line 1
func(arg=x := foo())
^^
SyntaxError: invalid syntaxI find this error pretty confusing. It's not clear why this is a syntax error or what users should do it fix it (i.e. add parentheses).
I propose adding a specialized syntax error to point users in the right direction, similar to what's currently done for assert:
>>> assert x := 1
File "<python-input-12>", line 1
assert x := 1
^^^^^^
SyntaxError: cannot use named expression without parentheses hereHas this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-parsertype-featureA feature request or enhancementA feature request or enhancement