forked from Rust-related/RustPython
Add delete for object_set_dict #6
@@ -495,9 +495,17 @@ pub fn object_get_dict(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyDict
|
||||
obj.dict()
|
||||
.ok_or_else(|| vm.new_attribute_error("This object has no __dict__".to_owned()))
|
||||
}
|
||||
pub fn object_set_dict(obj: PyObjectRef, dict: PyDictRef, vm: &VirtualMachine) -> PyResult<()> {
|
||||
obj.set_dict(dict)
|
||||
.map_err(|_| vm.new_attribute_error("This object has no __dict__".to_owned()))
|
||||
pub fn object_set_dict(obj: PyObjectRef, dict: PySetterValue<PyDictRef>, vm: &VirtualMachine) -> PyResult<()> {
|
||||
match dict {
|
||||
PySetterValue::Some(dict) => {
|
||||
obj.set_dict(dict)
|
||||
.map_err(|_| vm.new_attribute_error("This object has no __dict__".to_owned()))
|
||||
}
|
||||
PySetterValue::None => {
|
||||
obj.delete_dict()
|
||||
.map_err(|_| vm.new_attribute_error("This object has no deletable __dict__".to_owned()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(ctx: &Context) {
|
||||
|
||||
Reference in New Issue
Block a user