Commit 8de87a64 authored by Benjamin Peterson's avatar Benjamin Peterson

correctly lookup __dir__

parent 4ef33dc3
...@@ -1718,6 +1718,7 @@ order (MRO) for bases """ ...@@ -1718,6 +1718,7 @@ order (MRO) for bases """
("__exit__", run_context, swallow, set(), {"__enter__" : iden}), ("__exit__", run_context, swallow, set(), {"__enter__" : iden}),
("__complex__", complex, complex_num, set(), {}), ("__complex__", complex, complex_num, set(), {}),
("__format__", format, format_impl, set(), {}), ("__format__", format, format_impl, set(), {}),
("__dir__", dir, empty_seq, set(), {}),
] ]
class Checker(object): class Checker(object):
......
...@@ -9,6 +9,9 @@ What's New in Python 2.7.2? ...@@ -9,6 +9,9 @@ What's New in Python 2.7.2?
Core and Builtins 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, - Issue #1195: Fix input() if it is interrupted by CTRL+d and then CTRL+c,
clear the end-of-file indicator after CTRL+d. clear the end-of-file indicator after CTRL+d.
......
...@@ -1905,11 +1905,13 @@ static PyObject * ...@@ -1905,11 +1905,13 @@ static PyObject *
_dir_object(PyObject *obj) _dir_object(PyObject *obj)
{ {
PyObject *result = NULL; PyObject *result = NULL;
PyObject *dirfunc = PyObject_GetAttrString((PyObject *)obj->ob_type, static PyObject *dir_str = NULL;
"__dir__"); PyObject *dirfunc = _PyObject_LookupSpecial(obj, "__dir__", &dir_str);
assert(obj); assert(obj);
if (dirfunc == NULL) { if (dirfunc == NULL) {
if (PyErr_Occurred())
return NULL;
/* use default implementation */ /* use default implementation */
PyErr_Clear(); PyErr_Clear();
if (PyModule_Check(obj)) if (PyModule_Check(obj))
...@@ -1921,7 +1923,7 @@ _dir_object(PyObject *obj) ...@@ -1921,7 +1923,7 @@ _dir_object(PyObject *obj)
} }
else { else {
/* use __dir__ */ /* use __dir__ */
result = PyObject_CallFunctionObjArgs(dirfunc, obj, NULL); result = PyObject_CallFunctionObjArgs(dirfunc, NULL);
Py_DECREF(dirfunc); Py_DECREF(dirfunc);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment