Add delete for object_set_dict
Some checks failed
CI / Run rust tests (ubuntu-latest) (pull_request) Failing after 5m7s
CI / Ensure compilation on various targets (pull_request) Failing after 1m15s
CI / Check the WASM package and demo (pull_request) Failing after 5m47s
PR Review / review (pull_request) Failing after 4s
CI / Run snippets and cpython tests (ubuntu-latest) (pull_request) Failing after 5m21s
CI / Check Rust code with rustfmt and clippy (pull_request) Failing after 29s
CI / Run tests under miri (pull_request) Failing after 4m25s
CI / Run snippets and cpython tests on wasm-wasi (pull_request) Failing after 3m0s
CI / Run rust tests (macos-latest) (pull_request) Has been cancelled
CI / Run rust tests (windows-latest) (pull_request) Has been cancelled
CI / Run snippets and cpython tests (macos-latest) (pull_request) Has been cancelled
CI / Run snippets and cpython tests (windows-latest) (pull_request) Has been cancelled

This commit is contained in:
Zion
2024-11-01 20:47:13 -04:00
committed by Myeongseon Choi
parent b333ffa781
commit 6181bf4a7a

View File

@@ -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) {