I used to unpack a long iterable expression like this:
In python 3.8.7:
>>> _, a, (*_), c = [1,2,3,4,5,6]
>>> a
2
>>> c
6
In python 3.10.7:
>>> _, a, (*_), c = [1,2,3,4,5,6]
File "<stdin>", line 1
_, a, (*_), c = [1,2,3,4,5,6]
^^
SyntaxError: cannot use starred expression here
I'm not sure which version of python between 3.8.7 and 3.10.7 introduced this backwards breaking behavior. What's the justification for this?
There's an official discussion here. The most relevant quote I can find is:
Also the current behavior allows
(*x), y = 1assignment. If(*x)is to be totally disallowed,(*x), y = 1should also be rejected.
I agree.
The final "I agree" is from Guido van Rossum.
The rationale for rejecting (*x) was:
Honestly this seems like a bug in 3.8 to me (if it indeed behaves like this):
>>> (*x), y (1, 2, 3)Every time I mistakenly tried (*x) I really meant (*x,), so it's surprising that (*x), y would be interpreted as (*x, y) rather than flagging (*x) as an error.
Please don't "fix" this even if it is a regression.
Also by Guido van Rossum. So it seems like (*x) was rejected because it looks too similar to unpacking into a singlet tuple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With