Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
[3.11] gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ (GH-113359)#114118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
[3.11] gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ (GH-113359) #114118
Changes from all commits
8c12e9667ac0542c882e0a4613e225d62fb618d128d72e989File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix rendering tracebacks for exceptions with a broken ``__getattr__``. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1199,6 +1199,36 @@ print_exception_notes(struct exception_print_context *ctx, PyObject *notes) | ||
| 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); | ||
iritkatriel marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| note = PyUnicode_FromFormat("Ignored error getting __notes__: %R", errvalue); | ||
| Py_XDECREF(type); | ||
| Py_XDECREF(errvalue); | ||
| Py_XDECREF(tback); | ||
| if (!note) { | ||
| goto error; | ||
perrinjerome marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| *notes = PyList_New(1); | ||
| if (!*notes) { | ||
| goto error; | ||
| } | ||
perrinjerome marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (PyList_SetItem(*notes, 0, note) < 0) { | ||
| Py_DECREF(*notes); | ||
| goto error; | ||
perrinjerome marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
| 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; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.