mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-28603: Fix formatting tracebacks for unhashable exceptions (#4014)
This commit is contained in:
parent
191e313820
commit
de86073a76
9 changed files with 114 additions and 9 deletions
|
@ -817,13 +817,21 @@ print_exception_recursive(PyObject *f, PyObject *value, PyObject *seen)
|
|||
|
||||
if (seen != NULL) {
|
||||
/* Exception chaining */
|
||||
if (PySet_Add(seen, value) == -1)
|
||||
PyObject *value_id = PyLong_FromVoidPtr(value);
|
||||
if (value_id == NULL || PySet_Add(seen, value_id) == -1)
|
||||
PyErr_Clear();
|
||||
else if (PyExceptionInstance_Check(value)) {
|
||||
PyObject *check_id = NULL;
|
||||
cause = PyException_GetCause(value);
|
||||
context = PyException_GetContext(value);
|
||||
if (cause) {
|
||||
res = PySet_Contains(seen, cause);
|
||||
check_id = PyLong_FromVoidPtr(cause);
|
||||
if (check_id == NULL) {
|
||||
res = -1;
|
||||
} else {
|
||||
res = PySet_Contains(seen, check_id);
|
||||
Py_DECREF(check_id);
|
||||
}
|
||||
if (res == -1)
|
||||
PyErr_Clear();
|
||||
if (res == 0) {
|
||||
|
@ -835,7 +843,13 @@ print_exception_recursive(PyObject *f, PyObject *value, PyObject *seen)
|
|||
}
|
||||
else if (context &&
|
||||
!((PyBaseExceptionObject *)value)->suppress_context) {
|
||||
res = PySet_Contains(seen, context);
|
||||
check_id = PyLong_FromVoidPtr(context);
|
||||
if (check_id == NULL) {
|
||||
res = -1;
|
||||
} else {
|
||||
res = PySet_Contains(seen, check_id);
|
||||
Py_DECREF(check_id);
|
||||
}
|
||||
if (res == -1)
|
||||
PyErr_Clear();
|
||||
if (res == 0) {
|
||||
|
@ -848,6 +862,7 @@ print_exception_recursive(PyObject *f, PyObject *value, PyObject *seen)
|
|||
Py_XDECREF(context);
|
||||
Py_XDECREF(cause);
|
||||
}
|
||||
Py_XDECREF(value_id);
|
||||
}
|
||||
print_exception(f, value);
|
||||
if (err != 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue