Skip to content

Commit b269c48

Browse files
committed
may_add_dict
1 parent 33ea50c commit b269c48

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

vm/src/builtins/type.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,10 +1068,16 @@ impl Constructor for PyType {
10681068
let member_count: usize = base_member_count + heaptype_member_count;
10691069

10701070
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+
10711077
// 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
10731079
// 2. __dict__ is in __slots__
1074-
if heaptype_slots.is_none() || add_dict {
1080+
if (heaptype_slots.is_none() && may_add_dict) || add_dict {
10751081
flags |= PyTypeFlags::HAS_DICT | PyTypeFlags::MANAGED_DICT;
10761082
}
10771083

0 commit comments

Comments
 (0)