summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-05-23 21:11:05 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-05-23 21:11:05 (GMT)
commit7963a35b417dfde5d97c52c05b73af738c827ca6 (patch)
tree9b2d29889b2f44a65e518fb56e8291059e0363ce
parent2cca0572848817791537efc9ee5df66d4ceb2d42 (diff)
downloadcpython-7963a35b417dfde5d97c52c05b73af738c827ca6.zip
cpython-7963a35b417dfde5d97c52c05b73af738c827ca6.tar.gz
cpython-7963a35b417dfde5d97c52c05b73af738c827ca6.tar.bz2
correctly lookup __dir__
-rw-r--r--Lib/test/test_descr.py1
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/object.c11
3 files changed, 10 insertions, 5 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index aafe428..c74e232 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1595,6 +1595,7 @@ order (MRO) for bases """
# probably not worth it.
# ("__enter__", run_context, iden),
# ("__exit__", run_context, iden),
+ ("__dir__", dir, empty_seq, set(), {}),
]
class Checker(object):
diff --git a/Misc/NEWS b/Misc/NEWS
index 9ae7979..37bbbc1 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.1.4?
Core and Builtins
-----------------
+- Correct lookup of __dir__ on objects. Among other things, this causes errors
+ besides AttributeError found on lookup to be propagated.
+
- Issue #12060: Use sig_atomic_t type and volatile keyword in the signal
module. Patch written by Charles-François Natali.
diff --git a/Objects/object.c b/Objects/object.c
index d534273..ac57cd7 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1348,14 +1348,15 @@ error:
static PyObject *
_dir_object(PyObject *obj)
{
- PyObject * result = NULL;
- PyObject * dirfunc = PyObject_GetAttrString((PyObject*)obj->ob_type,
- "__dir__");
+ PyObject *result = NULL;
+ 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))
result = _specialized_dir_module(obj);
else if (PyType_Check(obj))
@@ -1365,7 +1366,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;