]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (GH-96353)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 8 Sep 2022 11:46:53 +0000 (04:46 -0700)
committerGitHub <noreply@github.com>
Thu, 8 Sep 2022 11:46:53 +0000 (04:46 -0700)
(cherry picked from commit b9634ac776c24bc4d4a57859d884a94cdfe16043)

Co-authored-by: philg314 <110174000+philg314@users.noreply.github.com>
Lib/test/test_exceptions.py
Misc/NEWS.d/next/Core and Builtins/2022-08-28-10-51-19.gh-issue-96352.jTLD2d.rst [new file with mode: 0644]
Objects/object.c

index d9ea8a4872d7161d1ef9a0a6c9820b3e0f221440..5cdbfcdc7723b56d2d258be983c8f67606da8689 100644 (file)
@@ -1981,6 +1981,11 @@ class AttributeErrorTests(unittest.TestCase):
         except AttributeError as exc:
             self.assertEqual("bluch", exc.name)
             self.assertEqual(obj, exc.obj)
+        try:
+            object.__getattribute__(obj, "bluch")
+        except AttributeError as exc:
+            self.assertEqual("bluch", exc.name)
+            self.assertEqual(obj, exc.obj)
 
     def test_getattr_has_name_and_obj_for_method(self):
         class A:
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-08-28-10-51-19.gh-issue-96352.jTLD2d.rst b/Misc/NEWS.d/next/Core and Builtins/2022-08-28-10-51-19.gh-issue-96352.jTLD2d.rst
new file mode 100644 (file)
index 0000000..25ab967
--- /dev/null
@@ -0,0 +1,2 @@
+Fix :exc:`AttributeError` missing ``name`` and ``obj`` attributes in
+:meth:`object.__getattribute__`. Patch by Philip Georgi.
index 47c352e3d6405825e047309e0c27f7353f65f438..6d80d6df74103138fb06bccc5cf102eb58814447 100644 (file)
@@ -1319,6 +1319,8 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
         PyErr_Format(PyExc_AttributeError,
                      "'%.50s' object has no attribute '%U'",
                      tp->tp_name, name);
+
+        set_attribute_error_context(obj, name);
     }
   done:
     Py_XDECREF(descr);