Ammar Askar <am...@ammaraskar.com> added the comment:

Jacob, let's skip the 2.7 part of the report since that is EOL now. For 
reference, the full error on the latest Python is:

>>> a, b, c, d = [1, 2, 3]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: not enough values to unpack (expected 4, got 3)

>>> a, b = [1, 2, 3]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: too many values to unpack (expected 2)


The first example already behaves as Steven describes, it gives the expected 
and actual count. In the second example it's difficult to calculate the x for 
"expected 2, got x" in general. This is because the iterable being unpacked 
could be a generator. For example, consider:

>>> a, b = itertools.repeat(42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: too many values to unpack (expected 2)

However, we could improve the message if the object being unpacked does expose 
a length. I've attached a PR that does this, it makes the error look like:

>>> a, b = [1, 2, 3]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: too many values to unpack (expected 2, got 3)

Hopefully showing the amounts should help clarify why the error was thrown even 
if the wording seems a bit iffy.

----------
nosy: +ammar2

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40202>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to