[Python-checkins] cpython (2.7): correctly lookup __dir__
benjamin.peterson
python-checkins at python.org
Mon May 23 23:32:14 CEST 2011
http://hg.python.org/cpython/rev/b2fc6b9f850f
changeset: 70312:b2fc6b9f850f
branch: 2.7
parent: 70304:9d004a9a2ced
user: Benjamin Peterson <benjamin at python.org>
date: Mon May 23 16:11:05 2011 -0500
summary:
correctly lookup __dir__
files:
Lib/test/test_descr.py | 1 +
Misc/NEWS | 3 +++
Objects/object.c | 8 +++++---
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1718,6 +1718,7 @@
("__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):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@
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.
diff --git a/Objects/object.c b/Objects/object.c
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -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;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list