diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-05-09 17:21:13 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-05-09 17:21:13 (GMT) |
commit | 053c61f67cffb1b33210259236a1383051f10a9a (patch) | |
tree | ef8a684c8c626e5b6f1c88a6855f3baa3fee4d57 /Objects/enumobject.c | |
parent | be720e0369b6b8a97ceab4a4f8f8930911bd1b75 (diff) | |
download | cpython-053c61f67cffb1b33210259236a1383051f10a9a.zip cpython-053c61f67cffb1b33210259236a1383051f10a9a.tar.gz cpython-053c61f67cffb1b33210259236a1383051f10a9a.tar.bz2 |
Merged revisions 72495 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r72495 | benjamin.peterson | 2009-05-08 21:07:04 -0500 (Fri, 08 May 2009) | 1 line
lookup __reversed__ correctly as a special method
........
Diffstat (limited to 'Objects/enumobject.c')
-rw-r--r-- | Objects/enumobject.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Objects/enumobject.c b/Objects/enumobject.c index 955bbdc..f8e4072 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, |