From 5a2a681e6f243678fc59facc83ab7d3f05c42e8f Mon Sep 17 00:00:00 2001 From: philg314 <110174000+philg314@users.noreply.github.com> Date: Sun, 28 Aug 2022 06:49:22 +0200 Subject: [PATCH 1/3] Set AttributeError context in _PyObject_GenericGetAttrWithDict --- Objects/object.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Objects/object.c b/Objects/object.c index 9bbe0eef308fba..5781d83632b7c2 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1352,6 +1352,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); From 314d7ebf1031fb287199a57088329429bf30fa3e Mon Sep 17 00:00:00 2001 From: philg314 <110174000+philg314@users.noreply.github.com> Date: Sun, 28 Aug 2022 10:51:45 +0200 Subject: [PATCH 2/3] Add test --- Lib/test/test_exceptions.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index f8b05128e3f8b9..123bed6198c615 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -2099,6 +2099,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: From 88628d621484e320dd2665197da372844525d163 Mon Sep 17 00:00:00 2001 From: philg314 <110174000+philg314@users.noreply.github.com> Date: Sun, 28 Aug 2022 10:51:56 +0200 Subject: [PATCH 3/3] Add news --- .../2022-08-28-10-51-19.gh-issue-96352.jTLD2d.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-08-28-10-51-19.gh-issue-96352.jTLD2d.rst 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 00000000000000..25ab9678715a92 --- /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.