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

Method pop

crates/vm/src/builtins/list.rs:354–367  ·  view source on GitHub ↗
(&self, i: OptionalArg<isize>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

352
353 #[pymethod]
354 fn pop(&self, i: OptionalArg<isize>, vm: &VirtualMachine) -> PyResult {
355 let mut i = i.into_option().unwrap_or(-1);
356 let mut elements = self.borrow_vec_mut();
357 if i < 0 {
358 i += elements.len() as isize;
359 }
360 if elements.is_empty() {
361 Err(vm.new_index_error("pop from empty list"))
362 } else if i < 0 || i as usize >= elements.len() {
363 Err(vm.new_index_error("pop index out of range"))
364 } else {
365 Ok(elements.remove(i as usize))
366 }
367 }
368
369 #[pymethod]
370 fn remove(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {

Callers 1

freelist_popMethod · 0.45

Calls 6

into_optionMethod · 0.80
borrow_vec_mutMethod · 0.80
ErrClass · 0.50
lenMethod · 0.45
is_emptyMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected