| 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) { |