summaryrefslogtreecommitdiffstats
path: root/Objects/moduleobject.c
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-10-24 19:57:45 (GMT)
committerFred Drake <fdrake@acm.org>2000-10-24 19:57:45 (GMT)
commit661ea26b3d8621ad0acc0ed2f2036ab29355f8ff (patch)
treefcfe10c4656a3e18911cd3b41b7d8c942d707786 /Objects/moduleobject.c
parentbd6f4fba1bc66a18cc15d50ffdd33faedff5ac4c (diff)
downloadcpython-661ea26b3d8621ad0acc0ed2f2036ab29355f8ff.zip
cpython-661ea26b3d8621ad0acc0ed2f2036ab29355f8ff.tar.gz
cpython-661ea26b3d8621ad0acc0ed2f2036ab29355f8ff.tar.bz2
Ka-Ping Yee <ping@lfw.org>:
Changes to error messages to increase consistency & clarity. This (mostly) closes SourceForge patch #101839.
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r--Objects/moduleobject.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index c655e95..4267896 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -163,13 +163,22 @@ static PyObject *
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 @@ module_getattr(PyModuleObject *m, char *name)
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 @@ module_setattr(PyModuleObject *m, char *name, PyObject *v)
}
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