summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-05-09 02:07:04 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-05-09 02:07:04 (GMT)
commit809e22543f8bafd2df66fbe116ad49bbca5793f3 (patch)
treec301fd6cd73eda018a1b9c5b8ae1cf9ac5e108c5 /Objects
parent84ad84e0bb15e7c64109e88060afdcb60ae7b740 (diff)
downloadcpython-809e22543f8bafd2df66fbe116ad49bbca5793f3.zip
cpython-809e22543f8bafd2df66fbe116ad49bbca5793f3.tar.gz
cpython-809e22543f8bafd2df66fbe116ad49bbca5793f3.tar.bz2
lookup __reversed__ correctly as a special method
Diffstat (limited to 'Objects')
-rw-r--r--Objects/enumobject.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index b1e412d..12a226c 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -222,7 +222,8 @@ static PyObject *
reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
Py_ssize_t n;
- PyObject *seq;
+ PyObject *seq, *reversed_meth;
+ static PyObject *reversed_cache = NULL;
reversedobject *ro;
if (type == &PyReversed_Type && !_PyArg_NoKeywords("reversed()", kwds))
@@ -231,8 +232,12 @@ reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (!PyArg_UnpackTuple(args, "reversed", 1, 1, &seq) )
return NULL;
- if (PyObject_HasAttrString(seq, "__reversed__"))
- return PyObject_CallMethod(seq, "__reversed__", NULL);
+ reversed_meth = _PyObject_LookupSpecial(seq, "__reversed__", &reversed_cache);
+ if (reversed_meth != NULL) {
+ PyObject *res = PyObject_CallFunctionObjArgs(reversed_meth, NULL);
+ Py_DECREF(reversed_meth);
+ return res;
+ }
if (!PySequence_Check(seq)) {
PyErr_SetString(PyExc_TypeError,