diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-06-25 02:36:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-24 16:36:34 -0700 |
commit | 9cd366462b8c45c5cd9e99b76047b517cece939e (patch) | |
tree | 94f1544c6b39638c4b0d44e9dcba2be8f486aedd /Python | |
parent | [3.12] gh-106033: [docs] Improve C API GetItem & HasAttr notes. (GH-106047) (... (diff) | |
download | cpython-9cd366462b8c45c5cd9e99b76047b517cece939e.tar.gz cpython-9cd366462b8c45c5cd9e99b76047b517cece939e.tar.bz2 cpython-9cd366462b8c45c5cd9e99b76047b517cece939e.zip |
[3.12] gh-106033: Get rid of new occurrences of PyDict_GetItem and Py… (#106041)
[3.12] 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.
(cherry picked from commit 1d33d5378058671bfabb6f4d4b5bfd4726973ff9)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pythonrun.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 05e7b437086..99e2eec453e 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1100,15 +1100,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__), ¬es); + 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; } |