From: philg314 <110174000+philg314@users.noreply.github.com> Date: Thu, 8 Sep 2022 11:12:14 +0000 (+0200) Subject: gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (#96353) X-Git-Tag: v3.12.0a1~447 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b9634ac776c24bc4d4a57859d884a94cdfe16043;p=thirdparty%2FPython%2Fcpython.git gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (#96353) --- diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index f8b05128e3f8..123bed6198c6 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -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 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 69f78342fefa..26cdcef59ddd 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -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);