File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -1068,10 +1068,16 @@ impl Constructor for PyType {
1068
1068
let member_count: usize = base_member_count + heaptype_member_count;
1069
1069
1070
1070
let mut flags = PyTypeFlags :: heap_type_flags ( ) ;
1071
+
1072
+ // Check if we may add dict
1073
+ // We can only add a dict if the primary base class doesn't already have one
1074
+ // In CPython, this checks tp_dictoffset == 0
1075
+ let may_add_dict = !base. slots . flags . has_feature ( PyTypeFlags :: HAS_DICT ) ;
1076
+
1071
1077
// Add HAS_DICT and MANAGED_DICT if:
1072
- // 1. __slots__ is not defined, OR
1078
+ // 1. __slots__ is not defined AND base doesn't have dict , OR
1073
1079
// 2. __dict__ is in __slots__
1074
- if heaptype_slots. is_none ( ) || add_dict {
1080
+ if ( heaptype_slots. is_none ( ) && may_add_dict ) || add_dict {
1075
1081
flags |= PyTypeFlags :: HAS_DICT | PyTypeFlags :: MANAGED_DICT ;
1076
1082
}
1077
1083
You can’t perform that action at this time.
0 commit comments