]> granicus.if.org Git - python/commitdiff
PyErr_Print(): When printing a class exception, try to dig out the
authorBarry Warsaw <barry@python.org>
Tue, 16 Sep 1997 21:42:03 +0000 (21:42 +0000)
committerBarry Warsaw <barry@python.org>
Tue, 16 Sep 1997 21:42:03 +0000 (21:42 +0000)
__module__ string and if found, print <module>.<class>, unless
<module> == "exceptions".

Python/pythonrun.c

index 610ec7a1f50ba9a461493cf3dc695a7122368590..63646161eafa4ea8557754de8adf0b56da6c8505 100644 (file)
@@ -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);