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

Method generic_setattr

crates/vm/src/protocol/object.rs:184–218  ·  view source on GitHub ↗
(
        &self,
        attr_name: &Py<PyStr>,
        value: PySetterValue,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

182 // int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value)
183 #[cfg_attr(feature = "flame-it", flame)]
184 pub fn generic_setattr(
185 &self,
186 attr_name: &Py<PyStr>,
187 value: PySetterValue,
188 vm: &VirtualMachine,
189 ) -> PyResult<()> {
190 vm_trace!("object.__setattr__({:?}, {}, {:?})", self, attr_name, value);
191 if let Some(attr) = vm
192 .ctx
193 .interned_str(attr_name)
194 .and_then(|attr_name| self.get_class_attr(attr_name))
195 {
196 let descr_set = attr.class().slots.descr_set.load();
197 if let Some(descriptor) = descr_set {
198 return descriptor(&attr, self.to_owned(), value, vm);
199 }
200 }
201
202 if let Some(dict) = self.dict() {
203 if let PySetterValue::Assign(value) = value {
204 dict.set_item(attr_name, value, vm)?;
205 } else {
206 dict.del_item(attr_name, vm).map_err(|e| {
207 if e.fast_isinstance(vm.ctx.exceptions.key_error) {
208 vm.new_no_attribute_error(self.to_owned(), attr_name.to_owned())
209 } else {
210 e
211 }
212 })?;
213 }
214 Ok(())
215 } else {
216 Err(vm.new_no_attribute_error(self.to_owned(), attr_name.to_owned()))
217 }
218 }
219
220 pub fn generic_getattr(&self, name: &Py<PyStr>, vm: &VirtualMachine) -> PyResult {
221 self.generic_getattr_opt(name, None, vm)?

Callers 4

__setattr__Method · 0.80
__delattr__Method · 0.80
slot_setattroMethod · 0.80
__module_set_attrMethod · 0.80

Calls 12

descriptorClass · 0.85
interned_strMethod · 0.80
get_class_attrMethod · 0.80
fast_isinstanceMethod · 0.80
ErrClass · 0.50
loadMethod · 0.45
classMethod · 0.45
to_ownedMethod · 0.45
dictMethod · 0.45
set_itemMethod · 0.45
del_itemMethod · 0.45

Tested by

no test coverage detected