@@ -3825,9 +3825,17 @@ unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp)
38253825 if (w == NULL ) {
38263826 /* Iterator done, via error or exhaustion. */
38273827 if (!PyErr_Occurred ()) {
3828- PyErr_Format (PyExc_ValueError ,
3829- "need more than %d value%s to unpack" ,
3830- i , i == 1 ? "" : "s" );
3828+ if (argcntafter == -1 ) {
3829+ PyErr_Format (PyExc_ValueError ,
3830+ "not enough values to unpack (expected %d, got %d)" ,
3831+ argcnt , i );
3832+ }
3833+ else {
3834+ PyErr_Format (PyExc_ValueError ,
3835+ "not enough values to unpack "
3836+ "(expected at least %d, got %d)" ,
3837+ argcnt + argcntafter , i );
3838+ }
38313839 }
38323840 goto Error ;
38333841 }
@@ -3844,8 +3852,9 @@ unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp)
38443852 return 1 ;
38453853 }
38463854 Py_DECREF (w );
3847- PyErr_Format (PyExc_ValueError , "too many values to unpack "
3848- "(expected %d)" , argcnt );
3855+ PyErr_Format (PyExc_ValueError ,
3856+ "too many values to unpack (expected %d)" ,
3857+ argcnt );
38493858 goto Error ;
38503859 }
38513860
@@ -3857,8 +3866,9 @@ unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp)
38573866
38583867 ll = PyList_GET_SIZE (l );
38593868 if (ll < argcntafter ) {
3860- PyErr_Format (PyExc_ValueError , "need more than %zd values to unpack" ,
3861- argcnt + ll );
3869+ PyErr_Format (PyExc_ValueError ,
3870+ "not enough values to unpack (expected at least %d, got %zd)" ,
3871+ argcnt + argcntafter , argcnt + ll );
38623872 goto Error ;
38633873 }
38643874
0 commit comments