diff options
author | Raymond Hettinger <python@rcn.com> | 2002-06-05 23:12:45 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2002-06-05 23:12:45 (GMT) |
commit | c4c453f5ae0a245aa0dd59431c323911c47f2735 (patch) | |
tree | 12218c6354e18f6992ed5e7b6f92cd1a5ef3436d /Python | |
parent | f97b2d7dad06e48e3bc255f16329fda1dc966da4 (diff) | |
download | cpython-c4c453f5ae0a245aa0dd59431c323911c47f2735.zip cpython-c4c453f5ae0a245aa0dd59431c323911c47f2735.tar.gz cpython-c4c453f5ae0a245aa0dd59431c323911c47f2735.tar.bz2 |
Skip Montanaro's patch, SF 559833, exposing xrange type in builtins.
Also, added more regression tests to cover the new type and test its
conformity with range().
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 44 |
1 files changed, 1 insertions, 43 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index fba1b49..5aa6bc7 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1365,48 +1365,6 @@ These are exactly the valid indices for a list of 4 elements."; static PyObject * -builtin_xrange(PyObject *self, PyObject *args) -{ - long ilow = 0, ihigh = 0, istep = 1; - long n; - - if (PyTuple_Size(args) <= 1) { - if (!PyArg_ParseTuple(args, - "l;xrange() requires 1-3 int arguments", - &ihigh)) - return NULL; - } - else { - if (!PyArg_ParseTuple(args, - "ll|l;xrange() requires 1-3 int arguments", - &ilow, &ihigh, &istep)) - return NULL; - } - if (istep == 0) { - PyErr_SetString(PyExc_ValueError, "xrange() arg 3 must not be zero"); - return NULL; - } - if (istep > 0) - n = get_len_of_range(ilow, ihigh, istep); - else - n = get_len_of_range(ihigh, ilow, -istep); - if (n < 0) { - PyErr_SetString(PyExc_OverflowError, - "xrange() result has too many items"); - return NULL; - } - return PyRange_New(ilow, n, istep, 1); -} - -static char xrange_doc[] = -"xrange([start,] stop[, step]) -> xrange object\n\ -\n\ -Like range(), but instead of returning a list, returns an object that\n\ -generates the numbers in the range on demand. This is slightly slower\n\ -than range() but more memory efficient."; - - -static PyObject * builtin_raw_input(PyObject *self, PyObject *args) { PyObject *v = NULL; @@ -1860,7 +1818,6 @@ static PyMethodDef builtin_methods[] = { {"unichr", builtin_unichr, METH_VARARGS, unichr_doc}, #endif {"vars", builtin_vars, METH_VARARGS, vars_doc}, - {"xrange", builtin_xrange, METH_VARARGS, xrange_doc}, {"zip", builtin_zip, METH_VARARGS, zip_doc}, {NULL, NULL}, }; @@ -1909,6 +1866,7 @@ _PyBuiltin_Init(void) SETBUILTIN("super", &PySuper_Type); SETBUILTIN("tuple", &PyTuple_Type); SETBUILTIN("type", &PyType_Type); + SETBUILTIN("xrange", &PyRange_Type); /* Note that open() is just an alias of file(). */ SETBUILTIN("open", &PyFile_Type); |