diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-05-23 21:22:42 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-05-23 21:22:42 (GMT) |
commit | f5fcd33be9b21b148774d3fa2832bb0627e94809 (patch) | |
tree | 2c445e396ed3cd28b9d83d633f62c7708798364e | |
parent | 4b244ef2554bd6e35fb432ad9b55eae90f37b4db (diff) | |
parent | 7963a35b417dfde5d97c52c05b73af738c827ca6 (diff) | |
download | cpython-f5fcd33be9b21b148774d3fa2832bb0627e94809.zip cpython-f5fcd33be9b21b148774d3fa2832bb0627e94809.tar.gz cpython-f5fcd33be9b21b148774d3fa2832bb0627e94809.tar.bz2 |
merge 3.1
-rw-r--r-- | Lib/test/test_descr.py | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Objects/object.c | 11 |
3 files changed, 10 insertions, 5 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 6638116..e90e0b9 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1587,6 +1587,7 @@ order (MRO) for bases """ ("__floor__", math.floor, zero, set(), {}), ("__trunc__", math.trunc, zero, set(), {}), ("__ceil__", math.ceil, zero, set(), {}), + ("__dir__", dir, empty_seq, set(), {}), ] class Checker(object): @@ -13,6 +13,9 @@ Core and Builtins Library ------- +- Correct lookup of __dir__ on objects. Among other things, this causes errors + besides AttributeError found on lookup to be propagated. + - Issue #12124: zipimport doesn't keep a reference to zlib.decompress() anymore to be able to unload the module. diff --git a/Objects/object.c b/Objects/object.c index 17e5069..a91c46a 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1366,14 +1366,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)) @@ -1383,7 +1384,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; |