mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-122239: Add actual count in unbalanced unpacking error message when possible (#122244)
This commit is contained in:
parent
07f0bf5aa4
commit
3597642ed5
4 changed files with 83 additions and 3 deletions
|
@ -2148,6 +2148,17 @@ _PyEval_UnpackIterableStackRef(PyThreadState *tstate, _PyStackRef v_stackref,
|
|||
return 1;
|
||||
}
|
||||
Py_DECREF(w);
|
||||
|
||||
if (PyList_CheckExact(v) || PyTuple_CheckExact(v)
|
||||
|| PyDict_CheckExact(v)) {
|
||||
ll = PyDict_CheckExact(v) ? PyDict_Size(v) : Py_SIZE(v);
|
||||
if (ll > argcnt) {
|
||||
_PyErr_Format(tstate, PyExc_ValueError,
|
||||
"too many values to unpack (expected %d, got %zd)",
|
||||
argcnt, ll);
|
||||
goto Error;
|
||||
}
|
||||
}
|
||||
_PyErr_Format(tstate, PyExc_ValueError,
|
||||
"too many values to unpack (expected %d)",
|
||||
argcnt);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue