-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
gh-138275: Fix error messages incorrectly using "starred expression" #138283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
||
>>> *a = range(10) # doctest:+ELLIPSIS | ||
Traceback (most recent call last): | ||
... | ||
SyntaxError: starred assignment target must be in a list or tuple | ||
SyntaxError: starred target must be in a list or tuple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this one was ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs do use the term starred target, so starred assignment target is both inconsistent/incorrect and longer, though I do not feel strongly about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc uses the shorter term in the context of assignments (right?) Outside that context target could be something else, like a jump target. So I think it may not be clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc uses the shorter term in the context of assignments
Yes, in both instances of the usage of the term:
Assignment of an object to a target list, optionally enclosed in parentheses or
square brackets, is recursively defined as follows....
- If the target list contains one target prefixed with an asterisk, called a
"starred" target: The object must be an iterable with ...
Implements assignment with a starred target
We also use the term in codegen
to name our variables.
How about we add ... in assignment ...
instead, it is consistent with the other error messages, and clarifies the context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the same error for
for *a in []: pass
and
with contextlib.nullcontext([]) as *a: pass
So "in assignment" can be confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know now, what message we should use. Any suggestions Serhiy?
The message:
has been changed for consistency.
=
gets the error message saying "starred expressions" instead of "starred targets" #138275