comparison Python/bltinmodule.c @ 46606:af0ef04401bb

Fix nits in builtin next().
author Georg Brandl <georg@python.org>
date Wed, 30 Apr 2008 19:47:01 +0000
parents b2d93a960b98
children 58a0d5524f9a
comparison
equal deleted inserted replaced
46605:948bea96dd20 46606:af0ef04401bb
1046 1046
1047 if (!PyArg_UnpackTuple(args, "next", 1, 2, &it, &def)) 1047 if (!PyArg_UnpackTuple(args, "next", 1, 2, &it, &def))
1048 return NULL; 1048 return NULL;
1049 if (!PyIter_Check(it)) { 1049 if (!PyIter_Check(it)) {
1050 PyErr_Format(PyExc_TypeError, 1050 PyErr_Format(PyExc_TypeError,
1051 "%.200s object is not an iterator", it->ob_type->tp_name); 1051 "%.200s object is not an iterator",
1052 it->ob_type->tp_name);
1052 return NULL; 1053 return NULL;
1053 } 1054 }
1054 1055
1055 res = (*it->ob_type->tp_iternext)(it); 1056 res = (*it->ob_type->tp_iternext)(it);
1056 if (res == NULL) { 1057 if (res != NULL) {
1057 if (def) { 1058 return res;
1058 if (PyErr_Occurred() && 1059 } else if (def != NULL) {
1059 !PyErr_ExceptionMatches(PyExc_StopIteration)) 1060 if (PyErr_Occurred()) {
1061 if(!PyErr_ExceptionMatches(PyExc_StopIteration))
1060 return NULL; 1062 return NULL;
1061 PyErr_Clear(); 1063 PyErr_Clear();
1062 Py_INCREF(def); 1064 }
1063 return def; 1065 Py_INCREF(def);
1064 } else if (PyErr_Occurred()) { 1066 return def;
1065 return NULL; 1067 } else if (PyErr_Occurred()) {
1066 } else { 1068 return NULL;
1067 PyErr_SetNone(PyExc_StopIteration); 1069 } else {
1068 return NULL; 1070 PyErr_SetNone(PyExc_StopIteration);
1069 } 1071 return NULL;
1070 } 1072 }
1071 return res;
1072 } 1073 }
1073 1074
1074 PyDoc_STRVAR(next_doc, 1075 PyDoc_STRVAR(next_doc,
1075 "next(iterator[, default])\n\ 1076 "next(iterator[, default])\n\
1076 \n\ 1077 \n\