Skip to content

Commit 19b94bc

Browse files
gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (GH-96353)
(cherry picked from commit b9634ac) Co-authored-by: philg314 <[email protected]>
1 parent 3ae2be6 commit 19b94bc

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Lib/test/test_exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,11 @@ class A:
19811981
except AttributeError as exc:
19821982
self.assertEqual("bluch", exc.name)
19831983
self.assertEqual(obj, exc.obj)
1984+
try:
1985+
object.__getattribute__(obj, "bluch")
1986+
except AttributeError as exc:
1987+
self.assertEqual("bluch", exc.name)
1988+
self.assertEqual(obj, exc.obj)
19841989

19851990
def test_getattr_has_name_and_obj_for_method(self):
19861991
class A:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :exc:`AttributeError` missing ``name`` and ``obj`` attributes in
2+
:meth:`object.__getattribute__`. Patch by Philip Georgi.

Objects/object.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,8 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
13191319
PyErr_Format(PyExc_AttributeError,
13201320
"'%.50s' object has no attribute '%U'",
13211321
tp->tp_name, name);
1322+
1323+
set_attribute_error_context(obj, name);
13221324
}
13231325
done:
13241326
Py_XDECREF(descr);

0 commit comments

Comments
 (0)