mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-17 01:51:39 +09:00
cleanup and rustfmt
This commit is contained in:
@@ -5,7 +5,6 @@ use std::ops::DerefMut;
|
||||
|
||||
use num_traits::ToPrimitive;
|
||||
|
||||
|
||||
use crate::function::{OptionalArg, PyFuncArgs};
|
||||
use crate::pyobject::{IdProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol};
|
||||
use crate::vm::{ReprGuard, VirtualMachine};
|
||||
@@ -14,8 +13,8 @@ use super::objbool;
|
||||
use super::objint;
|
||||
use super::objiter;
|
||||
use super::objsequence::{
|
||||
get_elements, get_elements_cell, get_item, seq_equal, seq_ge, seq_gt, seq_le, seq_lt, seq_mul,
|
||||
PySliceableSequence, del_item,
|
||||
del_item, get_elements, get_elements_cell, get_item, seq_equal, seq_ge, seq_gt, seq_le, seq_lt,
|
||||
seq_mul, PySliceableSequence,
|
||||
};
|
||||
use super::objtype;
|
||||
use crate::obj::objtype::PyClassRef;
|
||||
@@ -312,27 +311,7 @@ impl PyListRef {
|
||||
|
||||
fn delitem(self, key: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
let mut elements = self.elements.borrow_mut();
|
||||
// if objtype::isinstance(&key, &vm.ctx.int_type()) {
|
||||
// let idx = objint::get_value(&key).to_i32().unwrap();
|
||||
// if let Some(_) = elements.get_pos(idx) {
|
||||
// elements.remove(idx as usize);
|
||||
// Ok(vm.get_none())
|
||||
// } else {
|
||||
// Err(vm.new_index_error("list index out of range".to_string()))
|
||||
// }
|
||||
|
||||
// } else {
|
||||
// panic!(
|
||||
// "TypeError: indexing type {:?} with index {:?} is not supported (yet?)",
|
||||
// elements, key
|
||||
// )
|
||||
// }
|
||||
del_item(
|
||||
vm,
|
||||
self.as_object(),
|
||||
elements.deref_mut(),
|
||||
key,
|
||||
)
|
||||
del_item(vm, self.as_object(), elements.deref_mut(), key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ impl<T: Clone> PySliceableSequence for Vec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait PySliceableSequenceMut : PySliceableSequence {
|
||||
pub trait PySliceableSequenceMut: PySliceableSequence {
|
||||
//fn set_slice<T: PySliceableSequence>(&self, range: Range<usize>, seq: T) -> Self;
|
||||
//fn set_slice_reverse<T: PySliceableSequence>(&self, range: Range<usize>, seq: T) -> Self;
|
||||
//fn set_stepped_slice<T: PySliceableSequence>(&self, range: Range<usize>, step: usize, seq: T) -> Self;
|
||||
@@ -162,15 +162,15 @@ pub trait PySliceableSequenceMut : PySliceableSequence {
|
||||
Some(1) => {
|
||||
self.del_slice(range);
|
||||
Ok(vm.get_none())
|
||||
},
|
||||
}
|
||||
Some(num) => {
|
||||
self.del_stepped_slice(range, num as usize);
|
||||
Ok(vm.get_none())
|
||||
},
|
||||
}
|
||||
None => {
|
||||
self.del_slice(range.start..range.start + 1);
|
||||
Ok(vm.get_none())
|
||||
},
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO what to delete here?
|
||||
@@ -187,15 +187,15 @@ pub trait PySliceableSequenceMut : PySliceableSequence {
|
||||
Some(1) => {
|
||||
self.del_slice(range);
|
||||
Ok(vm.get_none())
|
||||
},
|
||||
}
|
||||
Some(num) => {
|
||||
self.del_stepped_slice(range, num as usize);
|
||||
Ok(vm.get_none())
|
||||
},
|
||||
}
|
||||
None => {
|
||||
self.del_slice(range.end - 1..range.end);
|
||||
Ok(vm.get_none())
|
||||
},
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO what to del here?
|
||||
@@ -238,7 +238,6 @@ impl<T: Clone> PySliceableSequenceMut for Vec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_item(
|
||||
vm: &VirtualMachine,
|
||||
sequence: &PyObjectRef,
|
||||
@@ -285,7 +284,7 @@ pub fn get_item(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn del_item<T: PySliceableSequenceMut> (
|
||||
pub fn del_item<T: PySliceableSequenceMut>(
|
||||
vm: &VirtualMachine,
|
||||
sequence: &PyObjectRef,
|
||||
elements: &mut T,
|
||||
@@ -308,7 +307,6 @@ pub fn del_item<T: PySliceableSequenceMut> (
|
||||
}
|
||||
|
||||
if subscript.payload::<PySlice>().is_some() {
|
||||
|
||||
if sequence.payload::<PyList>().is_some() {
|
||||
elements.del_slice_items(vm, &subscript)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user