Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,12 @@ class X(object):
with self.assertRaises(AttributeError):
del X().a

# Inherit from object on purpose to check some backwards compatibility paths
class X(object):
__slots__ = "a"
with self.assertRaisesRegex(AttributeError, "'X' object has no attribute 'a'"):
X().a

def test_slots_special(self):
# Testing __dict__ and __weakref__ in __slots__...
class D(object):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Include the name of the type in unset __slots__ attribute errors. Patch by
Pablo Galindo
13 changes: 9 additions & 4 deletions Python/structmember.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down