Skip to content

Commit 7fe262b

Browse files
committed
throw error on nonempty slots and itemsize > 0
1 parent d3cf0b1 commit 7fe262b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_slot.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,13 @@ class C(A, B): __slots__ = ["__dict__", "__dict__"]
151151
with self.assertRaisesRegex(TypeError, '__weakref__ slot disallowed: either we already got one, or __itemsize__ != 0'):
152152
class C(A, B): __slots__ = ["__weakref__", "__weakref__"]
153153

154+
def test_itemsize_and_non_empty_slots(self):
155+
raised = False
156+
try:
157+
class C(tuple): __slots__ = ['a']
158+
except TypeError:
159+
raised = True
160+
assert raised
161+
154162
if __name__ == "__main__":
155163
unittest.main()

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,10 @@ private PythonClass typeMetaclass(VirtualFrame frame, String name, PTuple bases,
22932293
}
22942294
int slotlen = getListLenNode().execute(slotsStorage);
22952295

2296+
if (slotlen > 0 && hasItemSize) {
2297+
throw raise(TypeError, ErrorMessages.NONEMPTY_SLOTS_NOT_ALLOWED_FOR_SUBTYPE_OF_S, base);
2298+
}
2299+
22962300
for (int i = 0; i < slotlen; i++) {
22972301
String slotName;
22982302
Object element = getSlotItemNode().execute(frame, slotsStorage, i);

0 commit comments

Comments
 (0)