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

Function envobj_to_dict

crates/vm/src/stdlib/os.rs:2365–2387  ·  view source on GitHub ↗
(
    env: crate::function::ArgMapping,
    vm: &VirtualMachine,
)

Source from the content-addressed store, hash-verified

2363/// parking_lot locks are held by threads that no longer exist.
2364#[cfg(any(unix, windows))]
2365pub(crate) fn envobj_to_dict(
2366 env: crate::function::ArgMapping,
2367 vm: &VirtualMachine,
2368) -> PyResult<crate::builtins::PyDictRef> {
2369 let obj = env.obj();
2370 if let Some(dict) = obj.downcast_ref_if_exact::<crate::builtins::PyDict>(vm) {
2371 return Ok(dict.to_owned());
2372 }
2373 if let Some(inst_dict) = obj.dict()
2374 && let Ok(Some(data)) = inst_dict.get_item_opt("_data", vm)
2375 && let Some(dict) = data.downcast_ref_if_exact::<crate::builtins::PyDict>(vm)
2376 {
2377 return Ok(dict.to_owned());
2378 }
2379 let keys = vm.call_method(obj, "keys", ())?;
2380 let dict = vm.ctx.new_dict();
2381 for key in keys.get_iter(vm)?.into_iter::<PyObjectRef>(vm)? {
2382 let key = key?;
2383 let val = obj.get_item(&*key, vm)?;
2384 dict.set_item(&*key, val, vm)?;
2385 }
2386 Ok(dict)
2387}
2388
2389#[cfg(not(windows))]
2390use super::posix as platform;

Callers 2

execveFunction · 0.85
execveFunction · 0.85

Calls 9

get_item_optMethod · 0.80
new_dictMethod · 0.80
get_iterMethod · 0.80
objMethod · 0.45
to_ownedMethod · 0.45
dictMethod · 0.45
call_methodMethod · 0.45
get_itemMethod · 0.45
set_itemMethod · 0.45

Tested by

no test coverage detected