MCPcopy Index your code
hub / github.com/RustPython/RustPython / remove

Method remove

crates/vm/src/builtins/list.rs:370–381  ·  view source on GitHub ↗
(&self, needle: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

368
369 #[pymethod]
370 fn remove(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
371 let index = self.mut_index(vm, &needle)?;
372
373 if let Some(index) = index.into() {
374 // defer delete out of borrow
375 let is_inside_range = index < self.borrow_vec().len();
376 Ok(is_inside_range.then(|| self.borrow_vec_mut().remove(index)))
377 } else {
378 Err(vm.new_value_error(format!("'{}' is not in list", needle.str(vm)?)))
379 }
380 .map(drop)
381 }
382
383 fn _delitem(&self, needle: &PyObject, vm: &VirtualMachine) -> PyResult<()> {
384 match SequenceIndex::try_from_borrowed_object(vm, needle, "list")? {

Callers 1

popMethod · 0.45

Calls 7

mut_indexMethod · 0.80
borrow_vecMethod · 0.80
borrow_vec_mutMethod · 0.80
ErrClass · 0.50
mapMethod · 0.45
lenMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected