Message241473
As Raymond notes, this is a fairly harmless quirk - it changes a SyntaxError to an iterable length dependent ValueError:
>>> () = []
File "<stdin>", line 1
SyntaxError: can't assign to ()
>>> [] = ()
>>> [] = [1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: too many values to unpack (expected 0)
I only found out about this after being puzzled when a typo in a live demo at PyCon 2015 failed to fail as I expected after seeing the presenter type a "[]" into the LHS of an assignment instead of the intended "_".
Removing the data dependence to make the assignment fail immediately (even if never tested against a non-empty iterable) would involve making the handling of List_kind match that of Tuple_kind in the switch statement that eryksun quoted.
I don't think it's an urgent fix, but if someone wanted to fix it (including a new test), I think it would be a reasonable contribution to accept. |
|
Date |
User |
Action |
Args |
2015-04-19 02:47:53 | ncoghlan | set | recipients:
+ ncoghlan, rhettinger, Devin Jeanpierre, ezio.melotti, r.david.murray, martin.panter, eryksun, Cesar.Kawakami, Kyle.Buzsaki |
2015-04-19 02:47:53 | ncoghlan | set | messageid: <1429411673.53.0.0924127573429.issue23275@psf.upfronthosting.co.za> |
2015-04-19 02:47:53 | ncoghlan | link | issue23275 messages |
2015-04-19 02:47:53 | ncoghlan | create | |
|