Skip to content

may_add_dict #6084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
10 changes: 8 additions & 2 deletions vm/src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,10 +1068,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
Loading