Merge pull request #3450 from YYun-D/slice_reduce

implement `reduce` method to `PySlice`
This commit is contained in:
Jeong YunWon
2021-11-21 04:58:56 +09:00
committed by GitHub
2 changed files with 14 additions and 2 deletions

View File

@@ -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):

View File

@@ -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<Self>,
) -> PyResult<(
PyTypeRef,
(Option<PyObjectRef>, PyObjectRef, Option<PyObjectRef>),
)> {
Ok((
zelf.clone_class(),
(zelf.start.clone(), zelf.stop.clone(), zelf.step.clone()),
))
}
}
impl Comparable for PySlice {