[Python-checkins] cpython (2.7): handle old-style instances

benjamin.peterson python-checkins at python.org
Tue May 24 00:11:17 CEST 2011


http://hg.python.org/cpython/rev/90399e508ce3
changeset:   70322:90399e508ce3
branch:      2.7
parent:      70312:b2fc6b9f850f
user:        Benjamin Peterson <benjamin at python.org>
date:        Mon May 23 17:11:21 2011 -0500
summary:
  handle old-style instances

files:
  Objects/object.c |  13 ++++++++++---
  1 files changed, 10 insertions(+), 3 deletions(-)


diff --git a/Objects/object.c b/Objects/object.c
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1906,14 +1906,21 @@
 {
     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))

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list