diff options
author | Barry Warsaw <barry@python.org> | 1997-09-16 21:42:03 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1997-09-16 21:42:03 (GMT) |
commit | 2f5f6a2595d4796fea3aecc8e2ed8b800033ecca (patch) | |
tree | c58533257f016f2da78d0fe38cfce177bbc9b307 /Python | |
parent | b81b5c72db472f129821312282c248e272732046 (diff) | |
download | cpython-2f5f6a2595d4796fea3aecc8e2ed8b800033ecca.zip cpython-2f5f6a2595d4796fea3aecc8e2ed8b800033ecca.tar.gz cpython-2f5f6a2595d4796fea3aecc8e2ed8b800033ecca.tar.bz2 |
PyErr_Print(): When printing a class exception, try to dig out the
__module__ string and if found, print <module>.<class>, unless
<module> == "exceptions".
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pythonrun.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 610ec7a..6364616 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -745,13 +745,28 @@ PyErr_Print() /* Don't do anything else */ } else if (PyClass_Check(exception)) { - PyObject* className = - ((PyClassObject*)exception)->cl_name; - if (className == NULL) + PyClassObject* exc = (PyClassObject*)exception; + PyObject* className = exc->cl_name; + PyObject* moduleName = + PyDict_GetItemString(exc->cl_dict, "__module__"); + + if (moduleName == NULL) err = PyFile_WriteString("<unknown>", f); - else - err = PyFile_WriteObject(className, f, - Py_PRINT_RAW); + else { + char* modstr = PyString_AsString(moduleName); + if (modstr && strcmp(modstr, "exceptions")) + { + err = PyFile_WriteString(modstr, f); + err += PyFile_WriteString(".", f); + } + } + if (err == 0) { + if (className == NULL) + err = PyFile_WriteString("<unknown>", f); + else + err = PyFile_WriteObject(className, f, + Py_PRINT_RAW); + } } else err = PyFile_WriteObject(exception, f, Py_PRINT_RAW); |