]> granicus.if.org Git - python/commitdiff
correctly lookup __dir__
authorBenjamin Peterson <benjamin@python.org>
Mon, 23 May 2011 21:11:05 +0000 (16:11 -0500)
committerBenjamin Peterson <benjamin@python.org>
Mon, 23 May 2011 21:11:05 +0000 (16:11 -0500)
Lib/test/test_descr.py
Misc/NEWS
Objects/object.c

index 1fe0de582a32733ba27974bfb4f4f658071dc54a..dc18f336dfccc8b382902a4c296d51de53ed1f30 100644 (file)
@@ -1718,6 +1718,7 @@ order (MRO) for bases """
             ("__exit__", run_context, swallow, set(), {"__enter__" : iden}),
             ("__complex__", complex, complex_num, set(), {}),
             ("__format__", format, format_impl, set(), {}),
+            ("__dir__", dir, empty_seq, set(), {}),
             ]
 
         class Checker(object):
index 296d2c1646442c3bb1889c3f14ce38776b400a75..8b7d726c399cbbb8148f74fd710ac0ed4444a0b3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@ What's New in Python 2.7.2?
 Core and Builtins
 -----------------
 
+- Correct lookup of __dir__ on objects. Among other things, this causes errors
+  besides AttributeError found on lookup to be propagated.
+
 - Issue #1195: Fix input() if it is interrupted by CTRL+d and then CTRL+c,
   clear the end-of-file indicator after CTRL+d.
 
index b6ad5de4772803c26e0d2986e1753923ed4544e4..1e033d25e8a392284a2595c9d647c1ef2b65bbe9 100644 (file)
@@ -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;