mirror of https://github.com/python/cpython
gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (#96353)
This commit is contained in:
parent
3fedfcf19b
commit
b9634ac776
|
@ -2099,6 +2099,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:
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix :exc:`AttributeError` missing ``name`` and ``obj`` attributes in
|
||||
:meth:`object.__getattribute__`. Patch by Philip Georgi.
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue