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 @@ -1211,10 +1211,16 @@ impl Constructor for PyType {
12111211 let member_count: usize = base_member_count + heaptype_member_count;
12121212
12131213 let mut flags = PyTypeFlags :: heap_type_flags ( ) ;
1214+
1215+ // Check if we may add dict
1216+ // We can only add a dict if the primary base class doesn't already have one
1217+ // In CPython, this checks tp_dictoffset == 0
1218+ let may_add_dict = !base. slots . flags . has_feature ( PyTypeFlags :: HAS_DICT ) ;
1219+
12141220 // Add HAS_DICT and MANAGED_DICT if:
1215- // 1. __slots__ is not defined, OR
1221+ // 1. __slots__ is not defined AND base doesn't have dict , OR
12161222 // 2. __dict__ is in __slots__
1217- if heaptype_slots. is_none ( ) || add_dict {
1223+ if ( heaptype_slots. is_none ( ) && may_add_dict ) || add_dict {
12181224 flags |= PyTypeFlags :: HAS_DICT | PyTypeFlags :: MANAGED_DICT ;
12191225 }
12201226
You can’t perform that action at this time.
0 commit comments