mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
*sigh* deal with instances correctly
This commit is contained in:
parent
0a32f9c448
commit
784d455066
2 changed files with 18 additions and 1 deletions
|
|
@ -232,7 +232,18 @@ reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
if (!PyArg_UnpackTuple(args, "reversed", 1, 1, &seq) )
|
||||
return NULL;
|
||||
|
||||
reversed_meth = _PyObject_LookupSpecial(seq, "__reversed__", &reversed_cache);
|
||||
if (PyInstance_Check(seq)) {
|
||||
reversed_meth = PyObject_GetAttrString(seq, "__reversed__");
|
||||
if (reversed_meth == NULL) {
|
||||
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
||||
PyErr_Clear();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
reversed_meth = _PyObject_LookupSpecial(seq, "__reversed__",
|
||||
&reversed_cache);
|
||||
if (reversed_meth != NULL) {
|
||||
PyObject *res = PyObject_CallFunctionObjArgs(reversed_meth, NULL);
|
||||
Py_DECREF(reversed_meth);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue