diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-07-16 23:34:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-16 23:34:46 (GMT) |
commit | f783428a2313a729ca8b539c5a86ff114b9ff375 (patch) | |
tree | 0a7544bd351ea47745d7406bc1adba01e63f9681 /Python | |
parent | 6714dec5e104bdee4a0ed4d9966de27d1bfa1e3d (diff) | |
download | cpython-f783428a2313a729ca8b539c5a86ff114b9ff375.zip cpython-f783428a2313a729ca8b539c5a86ff114b9ff375.tar.gz cpython-f783428a2313a729ca8b539c5a86ff114b9ff375.tar.bz2 |
bpo-44655: Include the name of the type in unset __slots__ attribute errors (GH-27199)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/structmember.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Python/structmember.c b/Python/structmember.c index ba88e15..c7e3188 100644 --- a/Python/structmember.c +++ b/Python/structmember.c @@ -5,11 +5,11 @@ #include "structmember.h" // PyMemberDef PyObject * -PyMember_GetOne(const char *addr, PyMemberDef *l) +PyMember_GetOne(const char *obj_addr, PyMemberDef *l) { PyObject *v; - addr += l->offset; + const char* addr = obj_addr + l->offset; switch (l->type) { case T_BOOL: v = PyBool_FromLong(*(char*)addr); @@ -69,8 +69,13 @@ PyMember_GetOne(const char *addr, PyMemberDef *l) break; case T_OBJECT_EX: v = *(PyObject **)addr; - if (v == NULL) - PyErr_SetString(PyExc_AttributeError, l->name); + if (v == NULL) { + PyObject *obj = (PyObject *)obj_addr; + PyTypeObject *tp = Py_TYPE(obj); + PyErr_Format(PyExc_AttributeError, + "'%.200s' object has no attribute '%s'", + tp->tp_name, l->name); + } Py_XINCREF(v); break; case T_LONGLONG: |