>>> a, *b, c, d, e = Seq()
Traceback (most recent call last):
...
- ValueError: need more than 3 values to unpack
+ ValueError: not enough values to unpack (expected at least 4, got 3)
+
+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)
Unpacking a sequence where the test for too long raises a different kind of
error
if (w == NULL) {
/* Iterator done, via error or exhaustion. */
if (!PyErr_Occurred()) {
- PyErr_Format(PyExc_ValueError,
- "need more than %d value%s to unpack",
- i, i == 1 ? "" : "s");
+ if (argcntafter == -1) {
+ PyErr_Format(PyExc_ValueError,
+ "not enough values to unpack (expected %d, got %d)",
+ argcnt, i);
+ }
+ else {
+ PyErr_Format(PyExc_ValueError,
+ "not enough values to unpack "
+ "(expected at least %d, got %d)",
+ argcnt + argcntafter, i);
+ }
}
goto Error;
}
return 1;
}
Py_DECREF(w);
- PyErr_Format(PyExc_ValueError, "too many values to unpack "
- "(expected %d)", argcnt);
+ PyErr_Format(PyExc_ValueError,
+ "too many values to unpack (expected %d)",
+ argcnt);
goto Error;
}
ll = PyList_GET_SIZE(l);
if (ll < argcntafter) {
- PyErr_Format(PyExc_ValueError, "need more than %zd values to unpack",
- argcnt + ll);
+ PyErr_Format(PyExc_ValueError,
+ "not enough values to unpack (expected at least %d, got %zd)",
+ argcnt + argcntafter, argcnt + ll);
goto Error;
}