summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2015-04-15 21:08:45 (GMT)
committerR David Murray <rdmurray@bitdance.com>2015-04-15 21:08:45 (GMT)
commit4171bbe687904582329c7977d571686953275b45 (patch)
tree35b0ca3d4c7dc8acd81aba0e9a2ee0b4dc51e07b /Python/ceval.c
parent13a6ee0af45e2adc508489fb60a29069905331a7 (diff)
downloadcpython-4171bbe687904582329c7977d571686953275b45.zip
cpython-4171bbe687904582329c7977d571686953275b45.tar.gz
cpython-4171bbe687904582329c7977d571686953275b45.tar.bz2
#23949: Improve tuple unpacking error messages.
Patch by Arnon Yaari.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index d68cdc6..2f3d3ad 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3825,9 +3825,17 @@ unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp)
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;
}
@@ -3844,8 +3852,9 @@ unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp)
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;
}
@@ -3857,8 +3866,9 @@ unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp)
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;
}