Skip to content

Commit 5292a85

Browse files
jgarzikclaude
andcommitted
Fix __slots__ to accept list form, not just tuples
__build_class__ only accepted tuple for __slots__; list was silently ignored. Now accepts both tuple and list, matching Python 3.12 spec. Both forms properly suppress inst_dict and raise AttributeError for non-slot attribute assignment. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 681df79 commit 5292a85

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/builtins.asm

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,18 +1343,24 @@ DEF_FUNC builtin___build_class__
13431343
test edx, edx
13441344
jz .bc_no_slots
13451345

1346-
; Must be TAG_PTR and a tuple
1346+
; Must be TAG_PTR and a tuple or list
13471347
cmp edx, TAG_PTR
13481348
jne .bc_no_slots
13491349
extern tuple_type
1350+
extern list_type
13501351
mov rcx, [rax + PyObject.ob_type]
13511352
lea rdx, [rel tuple_type]
13521353
cmp rcx, rdx
1354+
je .bc_slots_tuple
1355+
lea rdx, [rel list_type]
1356+
cmp rcx, rdx
13531357
jne .bc_no_slots
13541358

1355-
; rax = slots tuple
1356-
mov rbx, rax ; rbx = slots tuple
1357-
mov r13, [rbx + PyTupleObject.ob_size] ; r13 = nslots
1359+
; rax = slots list — get size and item pointers (same layout as tuple for ob_size/ob_item)
1360+
.bc_slots_tuple:
1361+
; rax = slots sequence (tuple or list, both have ob_size at same offset)
1362+
mov rbx, rax ; rbx = slots sequence
1363+
mov r13, [rbx + PyTupleObject.ob_size] ; r13 = nslots (works for both)
13581364
test r13, r13
13591365
jz .bc_no_slots
13601366

0 commit comments

Comments
 (0)