summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 34cfb7f4b4..8cdbb3790f 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -14,7 +14,8 @@
#undef Yield /* undefine macro conflicting with <winbase.h> */
#include "pycore_interp.h" // PyInterpreterState.importlib
-#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
+#include "pycore_object.h" // _PyDebug_PrintTotalRefs(),
+ // _PyType_GetQualName()
#include "pycore_pyerrors.h" // _PyErr_Fetch
#include "pycore_pylifecycle.h" // _Py_UnhandledKeyboardInterrupt
#include "pycore_pystate.h" // _PyInterpreterState_GET()
@@ -892,36 +893,37 @@ print_exception(PyObject *f, PyObject *value)
/* Don't do anything else */
}
else {
- PyObject* moduleName;
- const char *className;
+ PyObject* modulename;
+
_Py_IDENTIFIER(__module__);
assert(PyExceptionClass_Check(type));
- className = PyExceptionClass_Name(type);
- if (className != NULL) {
- const char *dot = strrchr(className, '.');
- if (dot != NULL)
- className = dot+1;
- }
- moduleName = _PyObject_GetAttrId(type, &PyId___module__);
- if (moduleName == NULL || !PyUnicode_Check(moduleName))
+ modulename = _PyObject_GetAttrId(type, &PyId___module__);
+ if (modulename == NULL || !PyUnicode_Check(modulename))
{
- Py_XDECREF(moduleName);
+ Py_XDECREF(modulename);
+ PyErr_Clear();
err = PyFile_WriteString("<unknown>", f);
}
else {
- if (!_PyUnicode_EqualToASCIIId(moduleName, &PyId_builtins))
+ if (!_PyUnicode_EqualToASCIIId(modulename, &PyId_builtins))
{
- err = PyFile_WriteObject(moduleName, f, Py_PRINT_RAW);
+ err = PyFile_WriteObject(modulename, f, Py_PRINT_RAW);
err += PyFile_WriteString(".", f);
}
- Py_DECREF(moduleName);
+ Py_DECREF(modulename);
}
if (err == 0) {
- if (className == NULL)
- err = PyFile_WriteString("<unknown>", f);
- else
- err = PyFile_WriteString(className, f);
+ PyObject* qualname = _PyType_GetQualName((PyTypeObject *)type);
+ if (qualname == NULL || !PyUnicode_Check(qualname)) {
+ Py_XDECREF(qualname);
+ PyErr_Clear();
+ err = PyFile_WriteString("<unknown>", f);
+ }
+ else {
+ err = PyFile_WriteObject(qualname, f, Py_PRINT_RAW);
+ Py_DECREF(qualname);
+ }
}
}
if (err == 0 && (value != Py_None)) {