Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Lib/test/test_unpack_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,27 +319,27 @@
...
test.test_unpack_ex.BozoError

Now some general starred expressions (all fail).
Now some general starred targets/expressions (all fail).

>>> a, *b, c, *d, e = range(10) # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: multiple starred expressions in assignment
SyntaxError: multiple starred targets in assignment

>>> [*b, *c] = range(10) # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: multiple starred expressions in assignment
SyntaxError: multiple starred targets in assignment

>>> a,*b,*c,*d = range(4) # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: multiple starred expressions in assignment
SyntaxError: multiple starred targets in assignment

>>> *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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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?


>>> *a # doctest:+ELLIPSIS
Traceback (most recent call last):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Error messages incorrectly using the term "starred expression" have been
corrected.
4 changes: 2 additions & 2 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -3415,7 +3415,7 @@ unpack_helper(compiler *c, location loc, asdl_expr_seq *elts)
}
else if (elt->kind == Starred_kind) {
return _PyCompile_Error(c, loc,
"multiple starred expressions in assignment");
"multiple starred targets in assignment");
}
}
if (!seen_star) {
Expand Down Expand Up @@ -5289,7 +5289,7 @@ codegen_visit_expr(compiler *c, expr_ty e)
/* In all legitimate cases, the Starred node was already replaced
* by codegen_list/codegen_tuple. XXX: is that okay? */
return _PyCompile_Error(c, loc,
"starred assignment target must be in a list or tuple");
"starred target must be in a list or tuple");
default:
return _PyCompile_Error(c, loc,
"can't use starred expression here");
Expand Down
Loading