From 9687c64f9d19f5ae610cee770736330a3e1576be Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 23 May 2011 16:11:05 -0500 Subject: correctly lookup __dir__ --- Objects/object.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Objects') diff --git a/Objects/object.c b/Objects/object.c index b6ad5de477..1e033d25e8 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1905,11 +1905,13 @@ static PyObject * _dir_object(PyObject *obj) { PyObject *result = NULL; - PyObject *dirfunc = PyObject_GetAttrString((PyObject *)obj->ob_type, - "__dir__"); + static PyObject *dir_str = NULL; + PyObject *dirfunc = _PyObject_LookupSpecial(obj, "__dir__", &dir_str); assert(obj); if (dirfunc == NULL) { + if (PyErr_Occurred()) + return NULL; /* use default implementation */ PyErr_Clear(); if (PyModule_Check(obj)) @@ -1921,7 +1923,7 @@ _dir_object(PyObject *obj) } else { /* use __dir__ */ - result = PyObject_CallFunctionObjArgs(dirfunc, obj, NULL); + result = PyObject_CallFunctionObjArgs(dirfunc, NULL); Py_DECREF(dirfunc); if (result == NULL) return NULL; -- cgit v1.2.1