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

Method set_item

crates/vm/src/protocol/object.rs:743–769  ·  view source on GitHub ↗
(
        &self,
        needle: &K,
        value: PyObjectRef,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

741 }
742
743 pub fn set_item<K: DictKey + ?Sized>(
744 &self,
745 needle: &K,
746 value: PyObjectRef,
747 vm: &VirtualMachine,
748 ) -> PyResult<()> {
749 if let Some(dict) = self.downcast_ref_if_exact::<PyDict>(vm) {
750 return dict.set_item(needle, value, vm);
751 }
752
753 let mapping = self.mapping_unchecked();
754 if let Some(f) = mapping.slots().ass_subscript.load() {
755 let needle = needle.to_pyobject(vm);
756 return f(mapping, &needle, Some(value), vm);
757 }
758
759 let seq = self.sequence_unchecked();
760 if let Some(f) = seq.slots().ass_item.load() {
761 let i = needle.key_as_isize(vm)?;
762 return f(seq, i, Some(value), vm);
763 }
764
765 Err(vm.new_type_error(format!(
766 "'{}' does not support item assignment",
767 self.class()
768 )))
769 }
770
771 pub fn del_item<K: DictKey + ?Sized>(&self, needle: &K, vm: &VirtualMachine) -> PyResult<()> {
772 if let Some(dict) = self.downcast_ref_if_exact::<PyDict>(vm) {

Callers 1

generic_setattrMethod · 0.45

Calls 9

mapping_uncheckedMethod · 0.80
sequence_uncheckedMethod · 0.80
key_as_isizeMethod · 0.80
fFunction · 0.50
SomeClass · 0.50
ErrClass · 0.50
loadMethod · 0.45
slotsMethod · 0.45
to_pyobjectMethod · 0.45

Tested by

no test coverage detected