cpython: e63f19d0a651 (original) (raw)
--- a/Python/errors.c +++ b/Python/errors.c @@ -825,54 +825,76 @@ PyErr_WriteUnraisable(PyObject *obj) { _Py_IDENTIFIER(module); PyObject *f, *t, *v, *tb;
+ PyErr_Fetch(&t, &v, &tb); + f = PySys_GetObject("stderr");
- if (f != NULL && f != Py_None) {
if (obj) {[](#l1.14)
PyFile_WriteString("Exception ignored in: ", f);[](#l1.15)
PyFile_WriteObject(obj, f, 0);[](#l1.16)
PyFile_WriteString("\n", f);[](#l1.17)
}[](#l1.18)
PyTraceBack_Print(tb, f);[](#l1.19)
if (t) {[](#l1.20)
PyObject* moduleName;[](#l1.21)
char* className;[](#l1.22)
assert(PyExceptionClass_Check(t));[](#l1.23)
className = PyExceptionClass_Name(t);[](#l1.24)
if (className != NULL) {[](#l1.25)
char *dot = strrchr(className, '.');[](#l1.26)
if (dot != NULL)[](#l1.27)
className = dot+1;[](#l1.28)
}[](#l1.29)
- if (obj) {
if (PyFile_WriteString("Exception ignored in: ", f) < 0)[](#l1.34)
goto done;[](#l1.35)
if (PyFile_WriteObject(obj, f, 0) < 0)[](#l1.36)
goto done;[](#l1.37)
if (PyFile_WriteString("\n", f) < 0)[](#l1.38)
goto done;[](#l1.39)
- }
- assert(PyExceptionClass_Check(t));
- className = PyExceptionClass_Name(t);
- if (className != NULL) {
char *dot = strrchr(className, '.');[](#l1.51)
if (dot != NULL)[](#l1.52)
className = dot+1;[](#l1.53)
- }
moduleName = _PyObject_GetAttrId(t, &PyId___module__);[](#l1.56)
if (moduleName == NULL)[](#l1.57)
PyFile_WriteString("<unknown>", f);[](#l1.58)
else {[](#l1.59)
char* modstr = _PyUnicode_AsString(moduleName);[](#l1.60)
if (modstr &&[](#l1.61)
strcmp(modstr, "builtins") != 0)[](#l1.62)
{[](#l1.63)
PyFile_WriteString(modstr, f);[](#l1.64)
PyFile_WriteString(".", f);[](#l1.65)
}[](#l1.66)
}[](#l1.67)
if (className == NULL)[](#l1.68)
PyFile_WriteString("<unknown>", f);[](#l1.69)
else[](#l1.70)
PyFile_WriteString(className, f);[](#l1.71)
if (v && v != Py_None) {[](#l1.72)
PyFile_WriteString(": ", f);[](#l1.73)
PyFile_WriteObject(v, f, Py_PRINT_RAW);[](#l1.74)
}[](#l1.75)
PyFile_WriteString("\n", f);[](#l1.76)
Py_XDECREF(moduleName);[](#l1.77)
- moduleName = PyObject_GetAttrId(t, &PyId___module_);
- if (moduleName == NULL) {
PyErr_Clear();[](#l1.80)
if (PyFile_WriteString("<unknown>", f) < 0)[](#l1.81)
goto done;[](#l1.82)
- }
- else {
if (PyUnicode_CompareWithASCIIString(moduleName, "builtins") != 0) {[](#l1.85)
if (PyFile_WriteObject(moduleName, f, Py_PRINT_RAW) < 0)[](#l1.86)
goto done;[](#l1.87)
if (PyFile_WriteString(".", f) < 0)[](#l1.88)
goto done;[](#l1.89) }[](#l1.90)
PyErr_Clear(); /* Just in case */[](#l1.91)
- }
- if (className == NULL) {
if (PyFile_WriteString("<unknown>", f) < 0)[](#l1.94)
goto done;[](#l1.95)
- }
- else {
if (PyFile_WriteString(className, f) < 0)[](#l1.98)
} +goto done;[](#l1.99)
- if (v && v != Py_None) {
if (PyFile_WriteString(": ", f) < 0)[](#l1.103)
goto done;[](#l1.104)
if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)[](#l1.105)
goto done;[](#l1.106)
- }
- if (PyFile_WriteString("\n", f) < 0)
goto done;[](#l1.109)