]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-148119: Refactor `get_type_attr_as_size` to improve error handling in `structseq...
authorWulian233 <1055917385@qq.com>
Mon, 6 Apr 2026 12:11:30 +0000 (20:11 +0800)
committerGitHub <noreply@github.com>
Mon, 6 Apr 2026 12:11:30 +0000 (17:41 +0530)
Objects/structseq.c

index 8fa9cbba3bcce3b5b31a0da396d1f395555d7698..9130fe6a133b1e45eed9583e9718127113d57dab 100644 (file)
@@ -28,7 +28,11 @@ static Py_ssize_t
 get_type_attr_as_size(PyTypeObject *tp, PyObject *name)
 {
     PyObject *v = PyDict_GetItemWithError(_PyType_GetDict(tp), name);
-    if (v == NULL && !PyErr_Occurred()) {
+
+    if (v == NULL) {
+        if (PyErr_Occurred()) {
+            return -1;
+        }
         PyErr_Format(PyExc_TypeError,
                      "Missed attribute '%U' of type %s",
                      name, tp->tp_name);