mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #3450 from YYun-D/slice_reduce
implement `reduce` method to `PySlice`
This commit is contained in:
2
Lib/test/test_slice.py
vendored
2
Lib/test/test_slice.py
vendored
@@ -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):
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user