[Python-checkins] gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (GH-96353)

miss-islington webhook-mailer at python.org
Thu Sep 8 07:46:58 EDT 2022


https://github.com/python/cpython/commit/19b94bc136b188d3da5ab8d02b93eb55a48bc641
commit: 19b94bc136b188d3da5ab8d02b93eb55a48bc641
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-09-08T04:46:53-07:00
summary:

gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (GH-96353)

(cherry picked from commit b9634ac776c24bc4d4a57859d884a94cdfe16043)

Co-authored-by: philg314 <110174000+philg314 at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Core and Builtins/2022-08-28-10-51-19.gh-issue-96352.jTLD2d.rst
M Lib/test/test_exceptions.py
M Objects/object.c

diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index d9ea8a4872d7..5cdbfcdc7723 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1981,6 +1981,11 @@ class A:
         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
index 000000000000..25ab9678715a
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-08-28-10-51-19.gh-issue-96352.jTLD2d.rst	
@@ -0,0 +1,2 @@
+Fix :exc:`AttributeError` missing ``name`` and ``obj`` attributes in
+:meth:`object.__getattribute__`. Patch by Philip Georgi.
diff --git a/Objects/object.c b/Objects/object.c
index 47c352e3d640..6d80d6df7410 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -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);



More information about the Python-checkins mailing list