summaryrefslogtreecommitdiffstats
path: root/Objects/enumobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-02-10 09:33:39 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-02-10 09:33:39 (GMT)
commit029dba5a4078bc1e9dc262d24aaa481936af49d3 (patch)
treeedd2a1b4e38130d66c90a6909239e22851676472 /Objects/enumobject.c
parent5cab2e3a88903b0cea558ee01b8f5b9e5a31a797 (diff)
downloadcpython-029dba5a4078bc1e9dc262d24aaa481936af49d3.zip
cpython-029dba5a4078bc1e9dc262d24aaa481936af49d3.tar.gz
cpython-029dba5a4078bc1e9dc262d24aaa481936af49d3.tar.bz2
Make reversed() transparent with respect to length.
Diffstat (limited to 'Objects/enumobject.c')
-rw-r--r--Objects/enumobject.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index 3aac680..55595ce 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -230,6 +230,12 @@ reversed_next(reversedobject *ro)
return item;
}
+static int
+reversed_len(reversedobject *ro)
+{
+ return PyObject_Size(ro->seq);
+}
+
static PyObject *
reversed_reverse(reversedobject *ro, PyObject *unused)
{
@@ -244,6 +250,12 @@ PyDoc_STRVAR(reversed_doc,
static PyMethodDef reversed_methods[] = {
{"__reversed__", (PyCFunction)reversed_reverse,
METH_NOARGS, reversed_doc},
+ {NULL, NULL} /* sentinel */
+};
+
+static PySequenceMethods reversed_as_sequence = {
+ (inquiry)reversed_len, /* sq_length */
+ 0, /* sq_concat */
};
PyTypeObject PyReversed_Type = {
@@ -260,7 +272,7 @@ PyTypeObject PyReversed_Type = {
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
- 0, /* tp_as_sequence */
+ &reversed_as_sequence, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */