(
&self,
attr_name: &Py<PyStr>,
value: PySetterValue,
vm: &VirtualMachine,
)
| 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)? |
no test coverage detected