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

Method iterate_mapping_keys

crates/vm/src/frame.rs:6527–6549  ·  view source on GitHub ↗

Helper function to iterate over mapping keys using the keys() method. This ensures proper order preservation for OrderedDict and other custom mappings.

(
        vm: &VirtualMachine,
        mapping: &PyObject,
        func_str: &Wtf8,
        mut key_handler: F,
    )

Source from the content-addressed store, hash-verified

6525 /// Helper function to iterate over mapping keys using the keys() method.
6526 /// This ensures proper order preservation for OrderedDict and other custom mappings.
6527 fn iterate_mapping_keys<F>(
6528 vm: &VirtualMachine,
6529 mapping: &PyObject,
6530 func_str: &Wtf8,
6531 mut key_handler: F,
6532 ) -> PyResult<()>
6533 where
6534 F: FnMut(PyObjectRef) -> PyResult<()>,
6535 {
6536 let Some(keys_method) = vm.get_method(mapping.to_owned(), vm.ctx.intern_str("keys")) else {
6537 return Err(vm.new_type_error(format!(
6538 "{} argument after ** must be a mapping, not {}",
6539 func_str,
6540 mapping.class().name()
6541 )));
6542 };
6543
6544 let keys = keys_method?.call((), vm)?.get_iter(vm)?;
6545 while let PyIterReturn::Return(key) = keys.next(vm)? {
6546 key_handler(key)?;
6547 }
6548 Ok(())
6549 }
6550
6551 /// Vectorcall dispatch for Instruction::Call (positional args only).
6552 /// Uses vectorcall slot if available, otherwise falls back to FuncArgs.

Callers

nothing calls this directly

Calls 7

intern_strMethod · 0.80
get_iterMethod · 0.80
ErrClass · 0.50
get_methodMethod · 0.45
to_ownedMethod · 0.45
callMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected