summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorJérome Perrin <perrinjerome@gmail.com>2024-01-21 17:12:17 (GMT)
committerGitHub <noreply@github.com>2024-01-21 17:12:17 (GMT)
commit00e8c9ce9ef73fb6f64dde7f97a75e17fcaa7541 (patch)
tree8b233f29d6fb5921189af68067339a30a0935cfe /Python
parentafefa4a74cecc505a54094c6a0f129fcdc02060a (diff)
downloadcpython-00e8c9ce9ef73fb6f64dde7f97a75e17fcaa7541.zip
cpython-00e8c9ce9ef73fb6f64dde7f97a75e17fcaa7541.tar.gz
cpython-00e8c9ce9ef73fb6f64dde7f97a75e17fcaa7541.tar.bz2
[3.12] gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ (GH-113359) (#114173)
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index f4c5d39..5f3d249 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1165,6 +1165,37 @@ 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);
+ PyErr_NormalizeException(&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;
@@ -1183,7 +1214,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__), &notes) < 0) {
+ if (get_exception_notes(ctx, value, &notes) < 0) {
goto error;
}