Skip to content

Commit

Permalink
pythongh-96352: Set AttributeError context in _PyObject_GenericGetAtt…
Browse files Browse the repository at this point in the history
…rWithDict (python#96353)
  • Loading branch information
philg314 authored Sep 8, 2022
1 parent 3fedfcf commit b9634ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :exc:`AttributeError` missing ``name`` and ``obj`` attributes in
:meth:`object.__getattribute__`. Patch by Philip Georgi.
2 changes: 2 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b9634ac

Please sign in to comment.