diff options
author | Raymond Hettinger <python@rcn.com> | 2004-02-08 10:49:42 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-02-08 10:49:42 (GMT) |
commit | 06353f76beab69a538d3a55ca9b6df7e9754b999 (patch) | |
tree | 3d0caeac4f7b271d32c35333a6b4f47baedbfa46 /Objects | |
parent | 8a1a5945908c7a0b2b487a98431ff46ab934014a (diff) | |
download | cpython-06353f76beab69a538d3a55ca9b6df7e9754b999.zip cpython-06353f76beab69a538d3a55ca9b6df7e9754b999.tar.gz cpython-06353f76beab69a538d3a55ca9b6df7e9754b999.tar.bz2 |
Let reversed() work with itself.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/enumobject.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Objects/enumobject.c b/Objects/enumobject.c index 7ed58da..3aac680 100644 --- a/Objects/enumobject.c +++ b/Objects/enumobject.c @@ -230,11 +230,22 @@ reversed_next(reversedobject *ro) return item; } +static PyObject * +reversed_reverse(reversedobject *ro, PyObject *unused) +{ + return PyObject_GetIter(ro->seq); +} + PyDoc_STRVAR(reversed_doc, "reverse(sequence) -> reverse iterator over values of the sequence\n" "\n" "Return a reverse iterator"); +static PyMethodDef reversed_methods[] = { + {"__reversed__", (PyCFunction)reversed_reverse, + METH_NOARGS, reversed_doc}, +}; + PyTypeObject PyReversed_Type = { PyObject_HEAD_INIT(&PyType_Type) 0, /* ob_size */ @@ -266,7 +277,7 @@ PyTypeObject PyReversed_Type = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)reversed_next, /* tp_iternext */ - 0, /* tp_methods */ + reversed_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ |