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

Method index

crates/vm/src/builtins/tuple.rs:434–447  ·  view source on GitHub ↗
(
        &self,
        needle: PyObjectRef,
        range: OptionalRangeArgs,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

432
433 #[pymethod]
434 fn index(
435 &self,
436 needle: PyObjectRef,
437 range: OptionalRangeArgs,
438 vm: &VirtualMachine,
439 ) -> PyResult<usize> {
440 let (start, stop) = range.saturate(self.len(), vm)?;
441 for (index, element) in self.elements.iter().enumerate().take(stop).skip(start) {
442 if vm.identical_or_equal(element, &needle)? {
443 return Ok(index);
444 }
445 }
446 Err(vm.new_value_error("tuple.index(x): x not in tuple"))
447 }
448
449 fn _contains(&self, needle: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {
450 for element in &self.elements {

Callers

nothing calls this directly

Calls 7

saturateMethod · 0.80
identical_or_equalMethod · 0.80
ErrClass · 0.50
lenMethod · 0.45
skipMethod · 0.45
takeMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected