Mercurial > cpython-lru_cache-weakref
diff Objects/moduleobject.c @ 15318:8aa947e1eee8 legacy-trunk
Ka-Ping Yee <ping@lfw.org>:
Changes to error messages to increase consistency & clarity.
This (mostly) closes SourceForge patch #101839.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Tue, 24 Oct 2000 19:57:45 +0000 |
| parents | 6f6f965c5e2d |
| children | 986d1c3ccdde |
line wrap: on
line diff
--- a/Objects/moduleobject.c Tue Oct 24 17:16:32 2000 +0000 +++ b/Objects/moduleobject.c Tue Oct 24 19:57:45 2000 +0000 @@ -163,13 +163,22 @@ module_getattr(PyModuleObject *m, char *name) { PyObject *res; + char* modname; if (strcmp(name, "__dict__") == 0) { Py_INCREF(m->md_dict); return m->md_dict; } res = PyDict_GetItemString(m->md_dict, name); - if (res == NULL) - PyErr_SetString(PyExc_AttributeError, name); + if (res == NULL) { + modname = PyModule_GetName((PyObject *)m); + if (modname == NULL) { + PyErr_Clear(); + modname = "?"; + } + PyErr_Format(PyExc_AttributeError, + "'%.50s' module has no attribute '%.400s'", + modname, name); + } else Py_INCREF(res); return res; @@ -178,6 +187,7 @@ static int module_setattr(PyModuleObject *m, char *name, PyObject *v) { + char* modname; if (name[0] == '_' && strcmp(name, "__dict__") == 0) { PyErr_SetString(PyExc_TypeError, "read-only special attribute"); @@ -185,9 +195,16 @@ } if (v == NULL) { int rv = PyDict_DelItemString(m->md_dict, name); - if (rv < 0) - PyErr_SetString(PyExc_AttributeError, - "delete non-existing module attribute"); + if (rv < 0) { + modname = PyModule_GetName((PyObject *)m); + if (modname == NULL) { + PyErr_Clear(); + modname = "?"; + } + PyErr_Format(PyExc_AttributeError, + "'%.50s' module has no attribute '%.400s'", + modname, name); + } return rv; } else
