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

Method get_item_opt

crates/vm/src/builtins/dict.rs:659–676  ·  view source on GitHub ↗
(
        &self,
        key: &K,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

657 }
658
659 pub fn get_item_opt<K: DictKey + ?Sized>(
660 &self,
661 key: &K,
662 vm: &VirtualMachine,
663 ) -> PyResult<Option<PyObjectRef>> {
664 if self.exact_dict(vm) {
665 self.entries.get(vm, key)
666 // FIXME: check __missing__?
667 } else {
668 match self.as_object().get_item(key, vm) {
669 Ok(value) => Ok(Some(value)),
670 Err(e) if e.fast_isinstance(vm.ctx.exceptions.key_error) => {
671 self.missing_opt(key, vm)
672 }
673 Err(e) => Err(e),
674 }
675 }
676 }
677
678 /// Return a cached-entry hint for exact dict fast paths.
679 pub(crate) fn hint_for_key<K: DictKey + ?Sized>(

Callers 15

get_importerFunction · 0.80
get_dict_opt_u32Function · 0.80
get_dict_opt_u64Function · 0.80
_adaptFunction · 0.80
build_row_cast_mapMethod · 0.80
bind_parameters_nameMethod · 0.80
execute_instructionMethod · 0.80
specialize_load_attrMethod · 0.80
specialize_store_attrMethod · 0.80
generic_getattr_optMethod · 0.80

Calls 8

exact_dictMethod · 0.80
fast_isinstanceMethod · 0.80
missing_optMethod · 0.80
SomeClass · 0.50
ErrClass · 0.50
getMethod · 0.45
get_itemMethod · 0.45
as_objectMethod · 0.45

Tested by

no test coverage detected