Skip to content

Commit 5764104

Browse files
committed
may_add_dict
1 parent 2785bd8 commit 5764104

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

crates/vm/src/builtins/type.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)