diff options
author | Jérome Perrin <perrinjerome@gmail.com> | 2024-01-19 20:35:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-19 20:35:57 (GMT) |
commit | 20f7cf2c7f2e3fd170a27a3ded8cc80124ba9f2d (patch) | |
tree | d0da8000f27b13d1011512e92198a8e31e70ea43 /Python | |
parent | a4ad7a0ac5dad9e4e1b2dc17cdbc02dc763e625f (diff) | |
download | cpython-20f7cf2c7f2e3fd170a27a3ded8cc80124ba9f2d.zip cpython-20f7cf2c7f2e3fd170a27a3ded8cc80124ba9f2d.tar.gz cpython-20f7cf2c7f2e3fd170a27a3ded8cc80124ba9f2d.tar.bz2 |
[3.11] gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ (GH-113359) (#114118)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pythonrun.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 91c2ad3..d3c0c85 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1200,6 +1200,36 @@ error: } 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) { PyObject *notes = NULL; @@ -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; } |