File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -121,8 +121,6 @@ def test_interface_no_arg(self):
121
121
[repr (exc ), exc .__class__ .__name__ + '()' ])
122
122
self .interface_test_driver (results )
123
123
124
- # TODO: RUSTPYTHON - BaseException.__setstate__ method not implemented
125
- @unittest .expectedFailure
126
124
def test_setstate_refcount_no_crash (self ):
127
125
# gh-97591: Acquire strong reference before calling tp_hash slot
128
126
# in PyObject_SetAttr.
Original file line number Diff line number Diff line change @@ -647,6 +647,24 @@ impl PyRef<PyBaseException> {
647
647
vm. new_tuple ( ( self . class ( ) . to_owned ( ) , self . args ( ) ) )
648
648
}
649
649
}
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
+ }
650
668
}
651
669
652
670
impl Constructor for PyBaseException {
You can’t perform that action at this time.
0 commit comments