diff --git a/vm/src/builtins/object.rs b/vm/src/builtins/object.rs index f783ee017c..02036a3cd5 100644 --- a/vm/src/builtins/object.rs +++ b/vm/src/builtins/object.rs @@ -495,9 +495,17 @@ pub fn object_get_dict(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult 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, 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) {