]> granicus.if.org Git - python/commitdiff
handle old-style instances
authorBenjamin Peterson <benjamin@python.org>
Mon, 23 May 2011 22:11:21 +0000 (17:11 -0500)
committerBenjamin Peterson <benjamin@python.org>
Mon, 23 May 2011 22:11:21 +0000 (17:11 -0500)
Objects/object.c

index 1e033d25e8a392284a2595c9d647c1ef2b65bbe9..5cf15b6a40f0effa8238e13297e79875ae147aba 100644 (file)
@@ -1906,14 +1906,21 @@ _dir_object(PyObject *obj)
 {
     PyObject *result = NULL;
     static PyObject *dir_str = NULL;
-    PyObject *dirfunc = _PyObject_LookupSpecial(obj, "__dir__", &dir_str);
+    PyObject *dirfunc;
 
     assert(obj);
-    if (dirfunc == NULL) {
+    if (PyInstance_Check(obj)) {
+        dirfunc = PyObject_GetAttrString(obj, "__dir__");
+        if (dirfunc == NULL && !PyErr_ExceptionMatches(PyExc_AttributeError))
+            return NULL;
+    }
+    else {
+        dirfunc = _PyObject_LookupSpecial(obj, "__dir__", &dir_str);
         if (PyErr_Occurred())
             return NULL;
+    }
+    if (dirfunc == NULL) {
         /* use default implementation */
-        PyErr_Clear();
         if (PyModule_Check(obj))
             result = _specialized_dir_module(obj);
         else if (PyType_Check(obj) || PyClass_Check(obj))