gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (GH-96353)

(cherry picked from commit b9634ac776)

Co-authored-by: philg314 <110174000+philg314@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2022-09-08 04:43:52 -07:00 committed by GitHub
parent 0c443c2315
commit 99919d4e8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View file

@ -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:

View file

@ -0,0 +1,2 @@
Fix :exc:`AttributeError` missing ``name`` and ``obj`` attributes in
:meth:`object.__getattribute__`. Patch by Philip Georgi.

View file

@ -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);