mirror of https://github.com/python/cpython
Fix nits in builtin next().
This commit is contained in:
parent
b041fdaf94
commit
aaa6392a12
|
@ -1048,17 +1048,20 @@ builtin_next(PyObject *self, PyObject *args)
|
|||
return NULL;
|
||||
if (!PyIter_Check(it)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s object is not an iterator", it->ob_type->tp_name);
|
||||
"%.200s object is not an iterator",
|
||||
it->ob_type->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
res = (*it->ob_type->tp_iternext)(it);
|
||||
if (res == NULL) {
|
||||
if (def) {
|
||||
if (PyErr_Occurred() &&
|
||||
!PyErr_ExceptionMatches(PyExc_StopIteration))
|
||||
if (res != NULL) {
|
||||
return res;
|
||||
} else if (def != NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
if(!PyErr_ExceptionMatches(PyExc_StopIteration))
|
||||
return NULL;
|
||||
PyErr_Clear();
|
||||
}
|
||||
Py_INCREF(def);
|
||||
return def;
|
||||
} else if (PyErr_Occurred()) {
|
||||
|
@ -1067,8 +1070,6 @@ builtin_next(PyObject *self, PyObject *args)
|
|||
PyErr_SetNone(PyExc_StopIteration);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(next_doc,
|
||||
|
|
Loading…
Reference in New Issue