Content-Length: 317244 | pFad | http://github.com/RustPython/RustPython/commit/81753c1d9e53fb85e72c5f3aa665b3eeb4805c20

50 BaseException.__setstate__ · RustPython/RustPython@81753c1 · GitHub
Skip to content

Commit 81753c1

Browse files
committed
BaseException.__setstate__
1 parent 0a6e1e8 commit 81753c1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Lib/test/test_baseexception.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ def test_interface_no_arg(self):
121121
[repr(exc), exc.__class__.__name__ + '()'])
122122
self.interface_test_driver(results)
123123

124-
# TODO: RUSTPYTHON - BaseException.__setstate__ method not implemented
125-
@unittest.expectedFailure
126124
def test_setstate_refcount_no_crash(self):
127125
# gh-97591: Acquire strong reference before calling tp_hash slot
128126
# in PyObject_SetAttr.

vm/src/exceptions.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,21 @@ impl PyRef<PyBaseException> {
647647
vm.new_tuple((self.class().to_owned(), self.args()))
648648
}
649649
}
650+
651+
#[pymethod(magic)]
652+
fn setstate(self, state: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
653+
if !vm.is_none(&state) {
654+
let dict = state
655+
.downcast::<crate::builtins::PyDict>()
656+
.map_err(|_| vm.new_type_error("state is not a dictionary".to_owned()))?;
657+
658+
for (key, value) in &dict {
659+
let key_str = key.str(vm)?;
660+
self.as_object().set_attr(&key_str, value.clone(), vm)?;
661+
}
662+
}
663+
Ok(vm.ctx.none())
664+
}
650665
}
651666

652667
impl Constructor for PyBaseException {

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/RustPython/RustPython/commit/81753c1d9e53fb85e72c5f3aa665b3eeb4805c20

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy