gh-106033: Get rid of new occurrences of PyDict_GetItem and PyObject_HasAttr (GH-106034)

These functions are broken by design because they discard any exceptions raised
inside, including MemoryError and KeyboardInterrupt.  They should not be
used in new code.
This commit is contained in:
Serhiy Storchaka 2023-06-23 20:10:32 +03:00 committed by GitHub
parent 41ad4dfc04
commit 1d33d53780
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 34 deletions

View file

@ -1134,15 +1134,13 @@ print_exception_notes(struct exception_print_context *ctx, PyObject *value)
return 0;
}
if (!PyObject_HasAttr(value, &_Py_ID(__notes__))) {
return 0;
}
PyObject *notes = PyObject_GetAttr(value, &_Py_ID(__notes__));
if (notes == NULL) {
return -1;
PyObject *notes;
int res = _PyObject_LookupAttr(value, &_Py_ID(__notes__), &notes);
if (res <= 0) {
return res;
}
if (!PySequence_Check(notes) || PyUnicode_Check(notes) || PyBytes_Check(notes)) {
int res = 0;
res = 0;
if (write_indented_margin(ctx, f) < 0) {
res = -1;
}