diff Objects/object.c @ 70312:b2fc6b9f850f 2.7

correctly lookup __dir__
author Benjamin Peterson <benjamin@python.org>
date Mon, 23 May 2011 16:11:05 -0500
parents b36cb4602e21
children 90399e508ce3
line wrap: on
line diff
--- a/Objects/object.c	Mon May 23 15:29:24 2011 -0400
+++ b/Objects/object.c	Mon May 23 16:11:05 2011 -0500
@@ -1905,11 +1905,13 @@
 _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 @@
     }
     else {
         /* use __dir__ */
-        result = PyObject_CallFunctionObjArgs(dirfunc, obj, NULL);
+        result = PyObject_CallFunctionObjArgs(dirfunc, NULL);
         Py_DECREF(dirfunc);
         if (result == NULL)
             return NULL;