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

Method index

crates/vm/src/stdlib/_collections.rs:166–188  ·  view source on GitHub ↗
(
            &self,
            needle: PyObjectRef,
            range: OptionalRangeArgs,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

164
165 #[pymethod]
166 fn index(
167 &self,
168 needle: PyObjectRef,
169 range: OptionalRangeArgs,
170 vm: &VirtualMachine,
171 ) -> PyResult<usize> {
172 let start_state = self.state.load();
173
174 let (start, stop) = range.saturate(self.__len__(), vm)?;
175 let index = self.mut_index_range(vm, &needle, start..stop)?;
176 if start_state != self.state.load() {
177 Err(vm.new_runtime_error("deque mutated during iteration"))
178 } else if let Some(index) = index.into() {
179 Ok(index)
180 } else {
181 Err(vm.new_value_error(
182 needle
183 .repr(vm)
184 .map(|repr| format!("{repr} is not in deque"))
185 .unwrap_or_else(|_| String::new()),
186 ))
187 }
188 }
189
190 #[pymethod]
191 fn insert(&self, idx: i32, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {

Callers

nothing calls this directly

Calls 8

newFunction · 0.85
saturateMethod · 0.80
mut_index_rangeMethod · 0.80
ErrClass · 0.50
loadMethod · 0.45
__len__Method · 0.45
mapMethod · 0.45
reprMethod · 0.45

Tested by

no test coverage detected