MCPcopy Index your code
hub / github.com/RustPython/RustPython / init_slots

Method init_slots

crates/vm/src/builtins/type.rs:801–834  ·  view source on GitHub ↗
(&self, ctx: &Context)

Source from the content-addressed store, hash-verified

799 }
800
801 pub(crate) fn init_slots(&self, ctx: &Context) {
802 // Inherit slots from MRO (mro[0] is self, so skip it)
803 let mro: Vec<_> = self.mro.read()[1..].to_vec();
804 for base in mro.iter() {
805 self.inherit_slots(base);
806 }
807
808 // Wire dunder methods to slots
809 #[allow(clippy::mutable_key_type)]
810 let mut slot_name_set = std::collections::HashSet::new();
811
812 // mro[0] is self, so skip it; self.attributes is checked separately below
813 for cls in self.mro.read()[1..].iter() {
814 for &name in cls.attributes.read().keys() {
815 if name.as_bytes().starts_with(b"__") && name.as_bytes().ends_with(b"__") {
816 slot_name_set.insert(name);
817 }
818 }
819 }
820 for &name in self.attributes.read().keys() {
821 if name.as_bytes().starts_with(b"__") && name.as_bytes().ends_with(b"__") {
822 slot_name_set.insert(name);
823 }
824 }
825 // Sort for deterministic iteration order (important for slot processing)
826 let mut slot_names: Vec<_> = slot_name_set.into_iter().collect();
827 slot_names.sort_by_key(|name| name.as_str());
828 for attr_name in slot_names {
829 self.update_slot::<true>(attr_name, ctx);
830 }
831
832 Self::set_new(&self.slots, &self.base);
833 Self::set_alloc(&self.slots, &self.base);
834 }
835
836 fn set_new(slots: &PyTypeSlots, base: &Option<PyTypeRef>) {
837 if slots.flags.contains(PyTypeFlags::DISALLOW_INSTANTIATION) {

Callers 2

new_heap_innerMethod · 0.80
set_basesMethod · 0.80

Calls 13

newFunction · 0.85
to_vecMethod · 0.80
inherit_slotsMethod · 0.80
starts_withMethod · 0.80
ends_withMethod · 0.80
collectMethod · 0.80
readMethod · 0.45
iterMethod · 0.45
keysMethod · 0.45
as_bytesMethod · 0.45
insertMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected