From: Barry Warsaw Date: Tue, 16 Sep 1997 21:42:03 +0000 (+0000) Subject: PyErr_Print(): When printing a class exception, try to dig out the X-Git-Tag: v1.5a4~150 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f5f6a2595d4796fea3aecc8e2ed8b800033ecca;p=python PyErr_Print(): When printing a class exception, try to dig out the __module__ string and if found, print ., unless == "exceptions". --- diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 610ec7a1f5..63646161ea 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("", 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("", f); + else + err = PyFile_WriteObject(className, f, + Py_PRINT_RAW); + } } else err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);