Skip to content

Commit 9b71424

Browse files
committed
Use slice.xxx_index() methods in setslice and delslice
1 parent f2873a5 commit 9b71424

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

vm/src/obj/objlist.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ impl PyListRef {
210210
}
211211

212212
fn setslice(self, slice: PySliceRef, sec: PyIterable, vm: &VirtualMachine) -> PyResult {
213-
let step = slice.step.clone().unwrap_or_else(BigInt::one);
213+
let step = slice.step_index(vm)?.unwrap_or_else(BigInt::one);
214214

215215
if step.is_zero() {
216216
Err(vm.new_value_error("slice step cannot be zero".to_string()))
217217
} else if step.is_positive() {
218-
let range = self.get_slice_range(&slice.start, &slice.stop);
218+
let range = self.get_slice_range(&slice.start_index(vm)?, &slice.stop_index(vm)?);
219219
if range.start < range.end {
220220
match step.to_i32() {
221221
Some(1) => self._set_slice(range, sec, vm),
@@ -237,14 +237,14 @@ impl PyListRef {
237237
} else {
238238
// calculate the range for the reverse slice, first the bounds needs to be made
239239
// exclusive around stop, the lower number
240-
let start = &slice.start.as_ref().map(|x| {
240+
let start = &slice.start_index(vm)?.as_ref().map(|x| {
241241
if *x == (-1).to_bigint().unwrap() {
242242
self.get_len() + BigInt::one() //.to_bigint().unwrap()
243243
} else {
244244
x + 1
245245
}
246246
});
247-
let stop = &slice.stop.as_ref().map(|x| {
247+
let stop = &slice.stop_index(vm)?.as_ref().map(|x| {
248248
if *x == (-1).to_bigint().unwrap() {
249249
self.get_len().to_bigint().unwrap()
250250
} else {
@@ -552,9 +552,9 @@ impl PyListRef {
552552
}
553553

554554
fn delslice(self, slice: PySliceRef, vm: &VirtualMachine) -> PyResult {
555-
let start = &slice.start;
556-
let stop = &slice.stop;
557-
let step = slice.step.clone().unwrap_or_else(BigInt::one);
555+
let start = slice.start_index(vm)?;
556+
let stop = slice.stop_index(vm)?;
557+
let step = slice.step_index(vm)?.unwrap_or_else(BigInt::one);
558558

559559
if step.is_zero() {
560560
Err(vm.new_value_error("slice step cannot be zero".to_string()))

vm/src/obj/objslice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::function::{OptionalArg, PyFuncArgs};
2-
use crate::pyobject::{IdProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue};
2+
use crate::pyobject::{IdProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol};
33
use crate::vm::VirtualMachine;
44

55
use crate::obj::objint::PyInt;

0 commit comments

Comments
 (0)