Content-Length: 397751 | pFad | http://github.com/RustPython/RustPython/commit/9952c97edf94a82432c3ad9bc2c7ef43dc917e56

60 BaseException.__setstate__ (#5821) · RustPython/RustPython@9952c97 · GitHub
Skip to content

Commit 9952c97

Browse files
authored
BaseException.__setstate__ (#5821)
* docs * BaseException.__setstate__
2 parents 33af632 + a288b77 commit 9952c97

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

Lib/test/support/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,8 +1933,7 @@ def _check_tracemalloc():
19331933
"if tracemalloc module is tracing "
19341934
"memory allocations")
19351935

1936-
1937-
# TODO: RUSTPYTHON (comment out before)
1936+
# TODO: RUSTPYTHON; GC is not supported yet
19381937
# def check_free_after_iterating(test, iter, cls, args=()):
19391938
# class A(cls):
19401939
# def __del__(self):

Lib/test/test_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def test_numbers(self):
176176
self.assertEqual(a, b,
177177
msg="{0!r} != {1!r}; testcase={2!r}".format(a, b, testcase))
178178

179-
# TODO: RUSTPYTHON
179+
# TODO: RUSTPYTHON - requires UTF-32 encoding support in codecs and proper array reconstructor implementation
180180
@unittest.expectedFailure
181181
def test_unicode(self):
182182
teststr = "Bonne Journ\xe9e \U0002030a\U00020347"

Lib/test/test_baseexception.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_inheritance(self):
8383
exc_set = set(e for e in exc_set if not e.startswith('_'))
8484
# RUSTPYTHON specific
8585
exc_set.discard("JitError")
86-
# TODO: RUSTPYTHON; this will be officially introduced in Python 3.15
86+
# XXX: RUSTPYTHON; IncompleteInputError will be officially introduced in Python 3.15
8787
exc_set.discard("IncompleteInputError")
8888
self.assertEqual(len(exc_set), 0, "%s not accounted for" % exc_set)
8989

@@ -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
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,24 @@ 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+
if key_str.as_str().starts_with("__") {
661+
continue;
662+
}
663+
self.as_object().set_attr(&key_str, value.clone(), vm)?;
664+
}
665+
}
666+
Ok(vm.ctx.none())
667+
}
650668
}
651669

652670
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/9952c97edf94a82432c3ad9bc2c7ef43dc917e56

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy