[Python-checkins] CVS: python/dist/src/Objects iterobject.c,1.1.2.4,1.1.2.5 dictobject.c,2.73.2.1,2.73.2.2

Guido van Rossum gvanrossum@usw-pr-cvs1.sourceforge.net
Wed, 14 Mar 2001 08:17:29 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv28608/Objects

Modified Files:
      Tag: iter-branch
	iterobject.c dictobject.c 
Log Message:
Switch from IndexError to StopIteration to end the sequence.

Index: iterobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/Attic/iterobject.c,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -C2 -r1.1.2.4 -r1.1.2.5
*** iterobject.c	2001/03/13 16:22:16	1.1.2.4
--- iterobject.c	2001/03/14 16:17:27	1.1.2.5
***************
*** 36,40 ****
  		PyObject *item;
  		if (it->it_index >= PyList_GET_SIZE(seq)) {
! 			PyErr_SetObject(PyExc_IndexError, Py_None);
  			return NULL;
  		}
--- 36,40 ----
  		PyObject *item;
  		if (it->it_index >= PyList_GET_SIZE(seq)) {
! 			PyErr_SetObject(PyExc_StopIteration, Py_None);
  			return NULL;
  		}
***************
*** 44,48 ****
  		return item;
  	}
! 	return PySequence_GetItem(seq, it->it_index++);
  }
  
--- 44,54 ----
  		return item;
  	}
! 	else {
! 		PyObject *result = PySequence_GetItem(seq, it->it_index++);
! 		if (result == NULL &&
! 		    PyErr_ExceptionMatches(PyExc_IndexError))
! 			PyErr_SetObject(PyExc_StopIteration, Py_None);
! 		return result;
! 	}
  }
  
***************
*** 56,60 ****
  static PyMethodDef iter_methods[] = {
  	{"next",	(PyCFunction)iter_next,	METH_VARARGS,
! 	 "it.next() -- get the next value, or raise IndexError"},
  	{NULL,		NULL}		/* sentinel */
  };
--- 62,66 ----
  static PyMethodDef iter_methods[] = {
  	{"next",	(PyCFunction)iter_next,	METH_VARARGS,
! 	 "it.next() -- get the next value, or raise StopIteration"},
  	{NULL,		NULL}		/* sentinel */
  };
***************
*** 131,145 ****
  	if (result != NULL) {
  		if (PyObject_RichCompareBool(result, it->it_sentinel, Py_EQ)) {
! 			PyErr_SetObject(PyExc_IndexError, Py_None);
  			Py_DECREF(result);
  			result = NULL;
  		}
  	}
- 	else {
- 		if (PyErr_ExceptionMatches(PyExc_IndexError))
- 			PyErr_SetString(PyExc_TypeError,
- 					"callable in iterator raised "
- 					"unexpected IndexError");
- 	}
  	return result;
  }
--- 137,145 ----
  	if (result != NULL) {
  		if (PyObject_RichCompareBool(result, it->it_sentinel, Py_EQ)) {
! 			PyErr_SetObject(PyExc_StopIteration, Py_None);
  			Py_DECREF(result);
  			result = NULL;
  		}
  	}
  	return result;
  }
***************
*** 147,151 ****
  static PyMethodDef calliter_methods[] = {
  	{"next",	(PyCFunction)calliter_next,	METH_VARARGS,
! 	 "it.next() -- get the next value, or raise IndexError"},
  	{NULL,		NULL}		/* sentinel */
  };
--- 147,151 ----
  static PyMethodDef calliter_methods[] = {
  	{"next",	(PyCFunction)calliter_next,	METH_VARARGS,
! 	 "it.next() -- get the next value, or raise StopIteration"},
  	{NULL,		NULL}		/* sentinel */
  };

Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.73.2.1
retrieving revision 2.73.2.2
diff -C2 -r2.73.2.1 -r2.73.2.2
*** dictobject.c	2001/03/13 16:32:03	2.73.2.1
--- dictobject.c	2001/03/14 16:17:27	2.73.2.2
***************
*** 1369,1373 ****
  		return key;
  	}
! 	PyErr_SetObject(PyExc_IndexError, Py_None);
  	return NULL;
  }
--- 1369,1373 ----
  		return key;
  	}
! 	PyErr_SetObject(PyExc_StopIteration, Py_None);
  	return NULL;
  }
***************
*** 1382,1386 ****
  static PyMethodDef dictiter_methods[] = {
  	{"next",	(PyCFunction)dictiter_next,	METH_VARARGS,
! 	 "it.next() -- get the next value, or raise IndexError"},
  	{NULL,		NULL}		/* sentinel */
  };
--- 1382,1386 ----
  static PyMethodDef dictiter_methods[] = {
  	{"next",	(PyCFunction)dictiter_next,	METH_VARARGS,
! 	 "it.next() -- get the next value, or raise StopIteration"},
  	{NULL,		NULL}		/* sentinel */
  };