summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-09-08 11:43:52 (GMT)
committerGitHub <noreply@github.com>2022-09-08 11:43:52 (GMT)
commit99919d4e8a4eecda918d548e50ad65ecec2317b4 (patch)
treeb8260b243724c86166600feb1d70445811a41f9f
parent0c443c2315cad48ee15b16bbe94e3a032dd14153 (diff)
downloadcpython-99919d4e8a4eecda918d548e50ad65ecec2317b4.zip
cpython-99919d4e8a4eecda918d548e50ad65ecec2317b4.tar.gz
cpython-99919d4e8a4eecda918d548e50ad65ecec2317b4.tar.bz2
gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (GH-96353)
(cherry picked from commit b9634ac776c24bc4d4a57859d884a94cdfe16043) Co-authored-by: philg314 <110174000+philg314@users.noreply.github.com>
-rw-r--r--Lib/test/test_exceptions.py5
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2022-08-28-10-51-19.gh-issue-96352.jTLD2d.rst2
-rw-r--r--Objects/object.c2
3 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index ff1a028..d7133ad 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -2058,6 +2058,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 0000000..25ab967
--- /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 cb7853c..6a22f27 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);