diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-05-23 22:11:21 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-05-23 22:11:21 (GMT) |
commit | fd89af59e84b4c9032ac22e67e1b7b4fefbb601d (patch) | |
tree | c4917026ff4a44d9656a041da42bdc75bedc19c9 /Objects/object.c | |
parent | 8de87a640339165ad5448f468f98fce7819fe99d (diff) | |
download | cpython-fd89af59e84b4c9032ac22e67e1b7b4fefbb601d.zip cpython-fd89af59e84b4c9032ac22e67e1b7b4fefbb601d.tar.gz cpython-fd89af59e84b4c9032ac22e67e1b7b4fefbb601d.tar.bz2 |
handle old-style instances
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Objects/object.c b/Objects/object.c index 1e033d2..5cf15b6 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1906,14 +1906,21 @@ _dir_object(PyObject *obj) { 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)) |