summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-06-24 23:41:02 (GMT)
committerGitHub <noreply@github.com>2023-06-24 23:41:02 (GMT)
commitdbe416b82b8a4ba69d263b915167ea1650ff2412 (patch)
tree11c8d2be004563e48ec22f86cf83900a2e242e5c /Python
parentc69f29f879c27a6ae306db2a590102eb4d0d3701 (diff)
downloadcpython-dbe416b82b8a4ba69d263b915167ea1650ff2412.zip
cpython-dbe416b82b8a4ba69d263b915167ea1650ff2412.tar.gz
cpython-dbe416b82b8a4ba69d263b915167ea1650ff2412.tar.bz2
[3.11] gh-106033: Get rid of new occurrences of PyDict_GetItem and Py… (#106040)
[3.11] 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.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index efa22b0..03e366a 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1138,15 +1138,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)) {
- int res = 0;
+ res = 0;
if (write_indented_margin(ctx, f) < 0) {
res = -1;
}