summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-05-23 17:11:21 -0500
committerBenjamin Peterson <benjamin@python.org>2011-05-23 17:11:21 -0500
commit7384c85a664f22d4703aea4ceca6e1dc2a74cafa (patch)
treefb6d197d5f3a804771777e8c4c7e32a076b07cba
parent9687c64f9d19f5ae610cee770736330a3e1576be (diff)
downloadcpython-7384c85a664f22d4703aea4ceca6e1dc2a74cafa.tar.gz
handle old-style instances
-rw-r--r--Objects/object.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 1e033d25e8..5cf15b6a40 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))