From fd3a0f6d868534bd1dc9ab8d5e16c0b91f402c35 Mon Sep 17 00:00:00 2001 From: yyun-d Date: Sat, 20 Nov 2021 18:59:18 +0900 Subject: [PATCH 1/2] implement reduce method to PySlice Signed-off-by: yyun-d --- vm/src/builtins/slice.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vm/src/builtins/slice.rs b/vm/src/builtins/slice.rs index 99bcec732..68e5d6886 100644 --- a/vm/src/builtins/slice.rs +++ b/vm/src/builtins/slice.rs @@ -194,6 +194,20 @@ impl PySlice { let (start, stop, step) = self.inner_indices(length, vm)?; Ok(vm.new_tuple((start, stop, step))) } + + #[allow(clippy::type_complexity)] + #[pymethod(magic)] + fn reduce( + zelf: PyRef, + ) -> PyResult<( + PyTypeRef, + (Option, PyObjectRef, Option), + )> { + Ok(( + zelf.clone_class(), + (zelf.start.clone(), zelf.stop.clone(), zelf.step.clone()), + )) + } } impl Comparable for PySlice { From e49d7118b863994393f3c58bb90475220d3cae19 Mon Sep 17 00:00:00 2001 From: yyun-d Date: Sat, 20 Nov 2021 18:59:59 +0900 Subject: [PATCH 2/2] fix test_pickle in test_slice Signed-off-by: yyun-d --- Lib/test/test_slice.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/test/test_slice.py b/Lib/test/test_slice.py index ecdd92b6c..9e79775ac 100644 --- a/Lib/test/test_slice.py +++ b/Lib/test/test_slice.py @@ -234,8 +234,6 @@ class SliceTest(unittest.TestCase): x[1:2] = 42 self.assertEqual(tmp, [(slice(1, 2), 42)]) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_pickle(self): s = slice(10, 20, 3) for protocol in (0,1,2):