Skip to content

Commit b9634ac

Browse files
authored
gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (#96353)
1 parent 3fedfcf commit b9634ac

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
@@ -2099,6 +2099,11 @@ class A:
20992099
except AttributeError as exc:
21002100
self.assertEqual("bluch", exc.name)
21012101
self.assertEqual(obj, exc.obj)
2102+
try:
2103+
object.__getattribute__(obj, "bluch")
2104+
except AttributeError as exc:
2105+
self.assertEqual("bluch", exc.name)
2106+
self.assertEqual(obj, exc.obj)
21022107

21032108
def test_getattr_has_name_and_obj_for_method(self):
21042109
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
@@ -1351,6 +1351,8 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
13511351
PyErr_Format(PyExc_AttributeError,
13521352
"'%.50s' object has no attribute '%U'",
13531353
tp->tp_name, name);
1354+
1355+
set_attribute_error_context(obj, name);
13541356
}
13551357
done:
13561358
Py_XDECREF(descr);

0 commit comments

Comments
 (0)