diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-12-26 10:30:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-26 10:30:41 (GMT) |
commit | 13a6c098c215921e35004f9d3a9b70f601e56500 (patch) | |
tree | cda014f1d730c1b10abc45484b9e2cf7ea04aa33 /Python | |
parent | a8f4e15f3d33084862ddd3a7d58cd00034e94f16 (diff) | |
download | cpython-13a6c098c215921e35004f9d3a9b70f601e56500.zip cpython-13a6c098c215921e35004f9d3a9b70f601e56500.tar.gz cpython-13a6c098c215921e35004f9d3a9b70f601e56500.tar.bz2 |
bpo-32259: Make a TypeError message when unpack non-iterable more specific. (#4903)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 12 |
1 files changed, 10 insertions, 2 deletions
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 @@ 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); |