Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
may_add_dict
  • Loading branch information
youknowone committed Dec 28, 2025
commit a3c3ea0c9ce1cb712a21112af4a46b368412dac7
10 changes: 8 additions & 2 deletions crates/vm/src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,10 +1338,16 @@ impl Constructor for PyType {
let member_count: usize = base_member_count + heaptype_member_count;

let mut flags = PyTypeFlags::heap_type_flags();

// Check if we may add dict
// We can only add a dict if the primary base class doesn't already have one
// In CPython, this checks tp_dictoffset == 0
let may_add_dict = !base.slots.flags.has_feature(PyTypeFlags::HAS_DICT);

// Add HAS_DICT and MANAGED_DICT if:
// 1. __slots__ is not defined, OR
// 1. __slots__ is not defined AND base doesn't have dict, OR
// 2. __dict__ is in __slots__
if heaptype_slots.is_none() || add_dict {
if (heaptype_slots.is_none() && may_add_dict) || add_dict {
flags |= PyTypeFlags::HAS_DICT | PyTypeFlags::MANAGED_DICT;
}

Expand Down