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)
4621
4621
}
4622
4622
4623
4623
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
+
4625
4637
type -> tp_members = _PyHeapType_GET_MEMBERS (et );
4626
4638
return 0 ;
4627
4639
}
You can’t perform that action at this time.
0 commit comments