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

Method init_dict

crates/vm/src/builtins/module.rs:255–272  ·  view source on GitHub ↗

TODO: should be on PyModule, not Py

(
        &self,
        name: &'static PyStrInterned,
        doc: Option<PyStrRef>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

253
254 // TODO: should be on PyModule, not Py<PyModule>
255 pub(crate) fn init_dict(
256 &self,
257 name: &'static PyStrInterned,
258 doc: Option<PyStrRef>,
259 vm: &VirtualMachine,
260 ) {
261 let dict = self.dict();
262 dict.set_item(identifier!(vm, __name__), name.to_object(), vm)
263 .expect("Failed to set __name__ on module");
264 dict.set_item(identifier!(vm, __doc__), doc.to_pyobject(vm), vm)
265 .expect("Failed to set __doc__ on module");
266 dict.set_item("__package__", vm.ctx.none(), vm)
267 .expect("Failed to set __package__ on module");
268 dict.set_item("__loader__", vm.ctx.none(), vm)
269 .expect("Failed to set __loader__ on module");
270 dict.set_item("__spec__", vm.ctx.none(), vm)
271 .expect("Failed to set __spec__ on module");
272 }
273
274 pub fn get_attr<'a>(&self, attr_name: impl AsPyStr<'a>, vm: &VirtualMachine) -> PyResult {
275 let attr_name = attr_name.as_pystr(&vm.ctx);

Callers 4

__init_dict_from_defMethod · 0.80
initMethod · 0.80
new_moduleMethod · 0.80
newMethod · 0.80

Calls 5

noneMethod · 0.80
dictMethod · 0.45
set_itemMethod · 0.45
to_objectMethod · 0.45
to_pyobjectMethod · 0.45

Tested by

no test coverage detected