]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (#96353)
authorphilg314 <110174000+philg314@users.noreply.github.com>
Thu, 8 Sep 2022 11:12:14 +0000 (13:12 +0200)
committerGitHub <noreply@github.com>
Thu, 8 Sep 2022 11:12:14 +0000 (12:12 +0100)
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 f8b05128e3f8b9438faed6fee973790697e895e2..123bed6198c6154268d4f1357381945dc418d93b 100644 (file)
@@ -2099,6 +2099,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 69f78342fefa1a30c2e1ed952c3042ff49242583..26cdcef59dddbd60dd44c0cdc02050b94e21666f 100644 (file)
@@ -1351,6 +1351,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);