File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -4621,7 +4621,19 @@ type_new_descriptors(const type_new_ctx *ctx, PyTypeObject *type)
46214621 }
46224622
46234623 type -> tp_basicsize = slotoffset ;
4624- type -> tp_itemsize = ctx -> base -> tp_itemsize ;
4624+
4625+ // Only inherit tp_itemsize if this type defines its own __slots__
4626+ // Classes that don't define __slots__ but inherit from __slots__ classes
4627+ // should not inherit tp_itemsize as they don't use variable-size items
4628+ if (et -> ht_slots != NULL && PyTuple_GET_SIZE (et -> ht_slots ) > 0 ) {
4629+ // This type defines its own __slots__, inherit tp_itemsize
4630+ type -> tp_itemsize = ctx -> base -> tp_itemsize ;
4631+ }
4632+ else {
4633+ // This type doesn't define __slots__, don't inherit tp_itemsize
4634+ type -> tp_itemsize = 0 ;
4635+ }
4636+
46254637 type -> tp_members = _PyHeapType_GET_MEMBERS (et );
46264638 return 0 ;
46274639}
You can’t perform that action at this time.
0 commit comments