bpo-32259: Make a TypeError message when unpack non-iterable more specific. (#4903)
diff --git a/Python/ceval.c b/Python/ceval.c
index 287f1df..9276755 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4137,8 +4137,16 @@
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);