summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-09-24 21:23:05 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-09-24 21:23:05 (GMT)
commit6b27cda64386195cd07dfb686e9486f1c4bc3159 (patch)
tree277a5c96e9683c63b573b508f8c4bd2d1374aed8 /Modules/itertoolsmodule.c
parent9ceebd544516908e67c0f0d92c7a5f484e12beeb (diff)
downloadcpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.zip
cpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.tar.gz
cpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.tar.bz2
Convert iterator __len__() methods to a private API.
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 34b37be..5ec5b8d 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 */