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

Method load_global_or_builtin

crates/vm/src/frame.rs:6125–6148  ·  view source on GitHub ↗
(&self, name: &Py<PyStr>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

6123
6124 #[inline]
6125 fn load_global_or_builtin(&self, name: &Py<PyStr>, vm: &VirtualMachine) -> PyResult {
6126 if let Some(builtins_dict) = self.builtins_dict {
6127 // Fast path: both globals and builtins are exact dicts
6128 // SAFETY: builtins_dict is only set when globals is also exact dict
6129 let globals_exact = unsafe { PyExact::ref_unchecked(self.globals.as_ref()) };
6130 globals_exact
6131 .get_chain_exact(builtins_dict, name, vm)?
6132 .ok_or_else(|| {
6133 vm.new_name_error(format!("name '{name}' is not defined"), name.to_owned())
6134 })
6135 } else {
6136 // Slow path: builtins is not a dict, use generic __getitem__
6137 if let Some(value) = self.globals.get_item_opt(name, vm)? {
6138 return Ok(value);
6139 }
6140 self.builtins.get_item(name, vm).map_err(|e| {
6141 if e.fast_isinstance(vm.ctx.exceptions.key_error) {
6142 vm.new_name_error(format!("name '{name}' is not defined"), name.to_owned())
6143 } else {
6144 e
6145 }
6146 })
6147 }
6148 }
6149
6150 #[cfg_attr(feature = "flame-it", flame("Frame"))]
6151 fn import(&mut self, vm: &VirtualMachine, module_name: Option<&Py<PyStr>>) -> PyResult<()> {

Callers 1

execute_instructionMethod · 0.80

Calls 8

ok_or_elseMethod · 0.80
get_chain_exactMethod · 0.80
new_name_errorMethod · 0.80
get_item_optMethod · 0.80
fast_isinstanceMethod · 0.80
as_refMethod · 0.45
to_ownedMethod · 0.45
get_itemMethod · 0.45

Tested by

no test coverage detected