Fix issue #1553: An errornous __length_hint__ can make list() raise a
SystemError.
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 965d088..df5da5f 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1657,8 +1657,9 @@
/* Guess result size and allocate space. */
n = _PyObject_LengthHint(v);
if (n < 0) {
- if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
- !PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ if (PyErr_Occurred()
+ && !PyErr_ExceptionMatches(PyExc_TypeError)
+ && !PyErr_ExceptionMatches(PyExc_AttributeError)) {
Py_DECREF(it);
return NULL;
}