]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix nits in builtin next().
authorGeorg Brandl <georg@python.org>
Wed, 30 Apr 2008 19:47:01 +0000 (19:47 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 30 Apr 2008 19:47:01 +0000 (19:47 +0000)
Python/bltinmodule.c

index 199ebc087de8bab89b143112b961ec78b78a2241..585059f92f9ca747806ba0ad0a9086d91649f86c 100644 (file)
@@ -1048,27 +1048,28 @@ 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()) {
-                       return NULL;
-               } else {
-                       PyErr_SetNone(PyExc_StopIteration);
-                       return NULL;
                }
+               Py_INCREF(def);
+               return def;
+       } else if (PyErr_Occurred()) {
+               return NULL;
+       } else {
+               PyErr_SetNone(PyExc_StopIteration);
+               return NULL;
        }
-       return res;
 }
 
 PyDoc_STRVAR(next_doc,