bpo-32259: Make a TypeError message when unpack non-iterable more specific. (#4903)

This commit is contained in:
Serhiy Storchaka 2017-12-26 12:30:41 +02:00 committed by GitHub
parent a8f4e15f3d
commit 13a6c098c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 6 deletions

View file

@ -4137,8 +4137,16 @@ unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp)
assert(v != NULL);
it = PyObject_GetIter(v);
if (it == NULL)
goto Error;
if (it == NULL) {
if (PyErr_ExceptionMatches(PyExc_TypeError) &&
v->ob_type->tp_iter == NULL && !PySequence_Check(v))
{
PyErr_Format(PyExc_TypeError,
"cannot unpack non-iterable %.200s object",
v->ob_type->tp_name);
}
return 0;
}
for (; i < argcnt; i++) {
w = PyIter_Next(it);