mirror of https://github.com/python/cpython.git
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:
parent
3ae2be69cc
commit
19b94bc136
|
@ -1981,6 +1981,11 @@ class A:
|
||||||
except AttributeError as exc:
|
except AttributeError as exc:
|
||||||
self.assertEqual("bluch", exc.name)
|
self.assertEqual("bluch", exc.name)
|
||||||
self.assertEqual(obj, exc.obj)
|
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):
|
def test_getattr_has_name_and_obj_for_method(self):
|
||||||
class A:
|
class A:
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix :exc:`AttributeError` missing ``name`` and ``obj`` attributes in
|
||||||
|
:meth:`object.__getattribute__`. Patch by Philip Georgi.
|
|
@ -1319,6 +1319,8 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
|
||||||
PyErr_Format(PyExc_AttributeError,
|
PyErr_Format(PyExc_AttributeError,
|
||||||
"'%.50s' object has no attribute '%U'",
|
"'%.50s' object has no attribute '%U'",
|
||||||
tp->tp_name, name);
|
tp->tp_name, name);
|
||||||
|
|
||||||
|
set_attribute_error_context(obj, name);
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
Py_XDECREF(descr);
|
Py_XDECREF(descr);
|
||||||
|
|
Loading…
Reference in New Issue