diff options
| author | Raymond Hettinger <python@rcn.com> | 2005-09-24 21:23:05 +0000 |
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2005-09-24 21:23:05 +0000 |
| commit | 0721428162222d11bcdf2944b55956b6e887ce97 (patch) | |
| tree | 4cefbefea4de1c14183e592e957d7a2aa89d7558 /Modules/itertoolsmodule.c | |
| parent | 36beb6e954cda2d9cb9cbe0dde89ccfc803a2ebd (diff) | |
| download | cpython-0721428162222d11bcdf2944b55956b6e887ce97.tar.gz | |
Convert iterator __len__() methods to a private API.
Diffstat (limited to 'Modules/itertoolsmodule.c')
| -rw-r--r-- | Modules/itertoolsmodule.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 34b37be43f..5ec5b8dde9 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -2336,17 +2336,21 @@ repeat_repr(repeatobject *ro) return result; } -static int +static PyObject * repeat_len(repeatobject *ro) { - if (ro->cnt == -1) + if (ro->cnt == -1) { PyErr_SetString(PyExc_TypeError, "len() of unsized object"); - return (int)(ro->cnt); + return NULL; + } + return PyInt_FromLong(ro->cnt); } -static PySequenceMethods repeat_as_sequence = { - (inquiry)repeat_len, /* sq_length */ - 0, /* sq_concat */ +PyDoc_STRVAR(length_cue_doc, "Private method returning an estimate of len(list(it))."); + +static PyMethodDef repeat_methods[] = { + {"_length_cue", (PyCFunction)repeat_len, METH_NOARGS, length_cue_doc}, + {NULL, NULL} /* sentinel */ }; PyDoc_STRVAR(repeat_doc, @@ -2368,7 +2372,7 @@ static PyTypeObject repeat_type = { 0, /* tp_compare */ (reprfunc)repeat_repr, /* tp_repr */ 0, /* tp_as_number */ - &repeat_as_sequence, /* tp_as_sequence */ + 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ @@ -2385,7 +2389,7 @@ static PyTypeObject repeat_type = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)repeat_next, /* tp_iternext */ - 0, /* tp_methods */ + repeat_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ |
