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

Method create_module

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

Create a module from this definition (Phase 1 of multi-phase init). This performs: 1. Create module object (using create slot if provided) 2. Initialize module dict from def 3. Add methods to module Does NOT add to sys.modules or call exec slot.

(&'static self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

52 ///
53 /// Does NOT add to sys.modules or call exec slot.
54 pub fn create_module(&'static self, vm: &VirtualMachine) -> PyResult<PyRef<PyModule>> {
55 use crate::PyPayload;
56
57 // Create module (use create slot if provided, else default creation)
58 let module = if let Some(create) = self.slots.create {
59 // Custom module creation
60 let spec = vm.ctx.new_str(self.name.as_str());
61 create(vm, spec.as_object(), self)?
62 } else {
63 // Default module creation
64 PyModule::from_def(self).into_ref(&vm.ctx)
65 };
66
67 // Initialize module dict and methods
68 PyModule::__init_dict_from_def(vm, &module);
69 module.__init_methods(vm)?;
70
71 Ok(module)
72 }
73
74 /// Execute the module's exec slot (Phase 2 of multi-phase init).
75 ///

Callers 3

module_execFunction · 0.45
import_builtinFunction · 0.45
init_moduleFunction · 0.45

Calls 6

__init_methodsMethod · 0.80
createFunction · 0.50
new_strMethod · 0.45
as_strMethod · 0.45
as_objectMethod · 0.45
into_refMethod · 0.45

Tested by

no test coverage detected