Skip to content
Closed
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
12 changes: 6 additions & 6 deletions Lib/test/test_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@
>>> a, b = t
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 2)
ValueError: too many values to unpack (expected 2) from object of type 'tuple'

Unpacking tuple of wrong size
Unpacking list of wrong size

>>> a, b = l
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 2)
ValueError: too many values to unpack (expected 2) from object of type 'list'

Unpacking sequence too short

>>> a, b, c, d = Seq()
Traceback (most recent call last):
...
ValueError: not enough values to unpack (expected 4, got 3)
ValueError: not enough values to unpack (expected 4, got 3) from object of type 'Seq'

Unpacking sequence too long

>>> a, b = Seq()
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 2)
ValueError: too many values to unpack (expected 2) from object of type 'Seq'

Unpacking a sequence where the test for too long raises a different kind of
error
Expand Down Expand Up @@ -136,7 +136,7 @@
>>> () = [42]
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 0)
ValueError: too many values to unpack (expected 0) from object of type 'list'

"""

Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_unpack_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@
>>> a, *b, c, d, e = Seq()
Traceback (most recent call last):
...
ValueError: not enough values to unpack (expected at least 4, got 3)
ValueError: not enough values to unpack (expected at least 4, got 3) from object of type 'Seq'

Unpacking sequence too short and target appears last

>>> a, b, c, d, *e = Seq()
Traceback (most recent call last):
...
ValueError: not enough values to unpack (expected at least 4, got 3)
ValueError: not enough values to unpack (expected at least 4, got 3) from object of type 'Seq'

Unpacking a sequence where the test for too long raises a different kind of
error
Expand Down
21 changes: 13 additions & 8 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4387,14 +4387,17 @@ unpack_iterable(PyThreadState *tstate, PyObject *v,
if (argcntafter == -1) {
_PyErr_Format(tstate, PyExc_ValueError,
"not enough values to unpack "
"(expected %d, got %d)",
argcnt, i);
"(expected %d, got %d) from object of type "
"'%.200s'",
argcnt, i, Py_TYPE(v)->tp_name);
}
else {
_PyErr_Format(tstate, PyExc_ValueError,
"not enough values to unpack "
"(expected at least %d, got %d)",
argcnt + argcntafter, i);
"(expected at least %d, got %d) from "
"object of type '%.200s'",
argcnt + argcntafter, i,
Py_TYPE(v)->tp_name);
}
}
goto Error;
Expand All @@ -4413,8 +4416,9 @@ unpack_iterable(PyThreadState *tstate, PyObject *v,
}
Py_DECREF(w);
_PyErr_Format(tstate, PyExc_ValueError,
"too many values to unpack (expected %d)",
argcnt);
"too many values to unpack (expected %d) from object "
"of type '%.200s'",
argcnt, Py_TYPE(v)->tp_name);
goto Error;
}

Expand All @@ -4427,8 +4431,9 @@ unpack_iterable(PyThreadState *tstate, PyObject *v,
ll = PyList_GET_SIZE(l);
if (ll < argcntafter) {
_PyErr_Format(tstate, PyExc_ValueError,
"not enough values to unpack (expected at least %d, got %zd)",
argcnt + argcntafter, argcnt + ll);
"not enough values to unpack (expected at least %d, got %zd) "
"from object of type '%.200s'",
argcnt + argcntafter, argcnt + ll, Py_TYPE(v)->tp_name);
goto Error;
}

Expand Down