mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
BaseException.__setstate__
This commit is contained in:
1 parent
0a6e1e80d7
commit
a288b77c4f
2 files changed
+18
-2
No files matched your search
Vendored
-2
@@ -121,8 +121,6 @@ class ExceptionClassTests(unittest.TestCase):
|
||||
[repr(exc), exc.__class__.__name__ + '()'])
|
||||
self.interface_test_driver(results)
|
||||
|
||||
# TODO: RUSTPYTHON - BaseException.__setstate__ method not implemented
|
||||
@unittest.expectedFailure
|
||||
def test_setstate_refcount_no_crash(self):
|
||||
# gh-97591: Acquire strong reference before calling tp_hash slot
|
||||
# in PyObject_SetAttr.
|
||||
|
||||
@@ -647,6 +647,24 @@ impl PyRef<PyBaseException> {
|
||||
vm.new_tuple((self.class().to_owned(), self.args()))
|
||||
}
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn setstate(self, state: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
|
||||
if !vm.is_none(&state) {
|
||||
let dict = state
|
||||
.downcast::<crate::builtins::PyDict>()
|
||||
.map_err(|_| vm.new_type_error("state is not a dictionary".to_owned()))?;
|
||||
|
||||
for (key, value) in &dict {
|
||||
let key_str = key.str(vm)?;
|
||||
if key_str.as_str().starts_with("__") {
|
||||
continue;
|
||||
}
|
||||
self.as_object().set_attr(&key_str, value.clone(), vm)?;
|
||||
}
|
||||
}
|
||||
Ok(vm.ctx.none())
|
||||
}
|
||||
}
|
||||
|
||||
impl Constructor for PyBaseException {
|
||||
|
||||
Reference in new issue
Block a user