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

Method fromkeys

crates/vm/src/builtins/dict.rs:272–294  ·  view source on GitHub ↗
(
        class: PyTypeRef,
        iterable: ArgIterable,
        value: OptionalArg<PyObjectRef>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

270impl PyDict {
271 #[pyclassmethod]
272 fn fromkeys(
273 class: PyTypeRef,
274 iterable: ArgIterable,
275 value: OptionalArg<PyObjectRef>,
276 vm: &VirtualMachine,
277 ) -> PyResult {
278 let value = value.unwrap_or_none(vm);
279 let d = PyType::call(&class, ().into(), vm)?;
280 match d.downcast_exact::<Self>(vm) {
281 Ok(pydict) => {
282 for key in iterable.iter(vm)? {
283 pydict.__setitem__(key?, value.clone(), vm)?;
284 }
285 Ok(pydict.into_pyref().into())
286 }
287 Err(pyobj) => {
288 for key in iterable.iter(vm)? {
289 pyobj.set_item(&*key?, value.clone(), vm)?;
290 }
291 Ok(pyobj)
292 }
293 }
294 }
295
296 pub fn __len__(&self) -> usize {
297 self.entries.len()

Callers

nothing calls this directly

Calls 7

into_pyrefMethod · 0.80
callFunction · 0.50
unwrap_or_noneMethod · 0.45
iterMethod · 0.45
__setitem__Method · 0.45
cloneMethod · 0.45
set_itemMethod · 0.45

Tested by

no test coverage detected