diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-04-24 23:29:23 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-04-24 23:29:23 (GMT) |
commit | 1184e266b92b2b9b5effccd570024c72de1363fe (patch) | |
tree | 9de0f9a1b726f8b50a6b255ddb51201bdd7af6f3 /Objects/moduleobject.c | |
parent | 7b9ff0e6da5371214b29053cdb96218e0d2eb655 (diff) | |
download | cpython-1184e266b92b2b9b5effccd570024c72de1363fe.zip cpython-1184e266b92b2b9b5effccd570024c72de1363fe.tar.gz cpython-1184e266b92b2b9b5effccd570024c72de1363fe.tar.bz2 |
do not override errors from descriptors on modules
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r-- | Objects/moduleobject.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 522ee5e..a3d9557 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -412,24 +412,23 @@ module_repr(PyModuleObject *m) } static PyObject* -module_getattr(PyObject *m, PyObject *name) +module_getattro(PyModuleObject *m, PyObject *name) { - PyModuleObject *module; PyObject *attr, *mod_name; - attr = PyObject_GenericGetAttr(m, name); - if (attr != NULL) + attr = PyObject_GenericGetAttr((PyObject *)m, name); + if (attr || !PyErr_ExceptionMatches(PyExc_AttributeError)) return attr; PyErr_Clear(); - module = (PyModuleObject*)m; - if (module->md_dict != NULL) { - mod_name = PyDict_GetItemString(module->md_dict, "__name__"); - if (mod_name != NULL) { + if (m->md_dict) { + mod_name = PyDict_GetItemString(m->md_dict, "__name__"); + if (mod_name) { PyErr_Format(PyExc_AttributeError, "module '%U' has no attribute '%U'", mod_name, name); return NULL; } - else if (PyErr_Occurred()) + else if (PyErr_Occurred()) { PyErr_Clear(); + } } PyErr_Format(PyExc_AttributeError, "module has no attribute '%U'", name); @@ -512,7 +511,7 @@ PyTypeObject PyModule_Type = { 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ - module_getattr, /* tp_getattro */ + (getattrofunc)module_getattro, /* tp_getattro */ PyObject_GenericSetAttr, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | |