This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ammar2
Recipients Jacob RR, ammar2, docs@python, steven.daprano
Date 2020-04-09.06:47:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1586414867.66.0.484489467409.issue40202@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-04-09 06:47:47ammar2setrecipients: + ammar2, steven.daprano, docs@python, Jacob RR
2020-04-09 06:47:47ammar2setmessageid: <1586414867.66.0.484489467409.issue40202@roundup.psfhosted.org>
2020-04-09 06:47:47ammar2linkissue40202 messages
2020-04-09 06:47:46ammar2create