mirror of
https://github.com/python/cpython.git
synced 2025-07-13 22:35:18 +00:00
[3.11] gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ (GH-113359) (#114118)
This commit is contained in:
parent
a4ad7a0ac5
commit
20f7cf2c7f
4 changed files with 52 additions and 2 deletions
|
@ -1199,6 +1199,36 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
get_exception_notes(struct exception_print_context *ctx, PyObject *value, PyObject **notes) {
|
||||
PyObject *note = NULL;
|
||||
|
||||
if (_PyObject_LookupAttr(value, &_Py_ID(__notes__), notes) < 0) {
|
||||
PyObject *type, *errvalue, *tback;
|
||||
PyErr_Fetch(&type, &errvalue, &tback);
|
||||
note = PyUnicode_FromFormat("Ignored error getting __notes__: %R", errvalue);
|
||||
Py_XDECREF(type);
|
||||
Py_XDECREF(errvalue);
|
||||
Py_XDECREF(tback);
|
||||
if (!note) {
|
||||
goto error;
|
||||
}
|
||||
*notes = PyList_New(1);
|
||||
if (!*notes) {
|
||||
goto error;
|
||||
}
|
||||
if (PyList_SetItem(*notes, 0, note) < 0) {
|
||||
Py_DECREF(*notes);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
error:
|
||||
Py_XDECREF(note);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
print_exception(struct exception_print_context *ctx, PyObject *value)
|
||||
{
|
||||
|
@ -1218,7 +1248,7 @@ print_exception(struct exception_print_context *ctx, PyObject *value)
|
|||
|
||||
/* grab the type and notes now because value can change below */
|
||||
PyObject *type = (PyObject *) Py_TYPE(value);
|
||||
if (_PyObject_LookupAttr(value, &_Py_ID(__notes__), ¬es) < 0) {
|
||||
if (get_exception_notes(ctx, value, ¬es) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue