[Python-checkins] cpython (merge 3.1 -> 3.2): merge 3.1
benjamin.peterson
python-checkins at python.org
Mon May 23 23:32:15 CEST 2011
http://hg.python.org/cpython/rev/19ffce6ea323
changeset: 70313:19ffce6ea323
branch: 3.2
parent: 70305:6f93b9be58a5
parent: 70311:bdfbe0b499af
user: Benjamin Peterson <benjamin at python.org>
date: Mon May 23 16:22:42 2011 -0500
summary:
merge 3.1
files:
Lib/test/test_descr.py | 1 +
Misc/NEWS | 3 +++
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
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1587,6 +1587,7 @@
("__floor__", math.floor, zero, set(), {}),
("__trunc__", math.trunc, zero, set(), {}),
("__ceil__", math.ceil, zero, set(), {}),
+ ("__dir__", dir, empty_seq, set(), {}),
]
class Checker(object):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@
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
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1366,14 +1366,15 @@
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 @@
}
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