File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ pub(crate) use gc::module_def;
22
33#[ pymodule]
44mod gc {
5- use crate :: vm:: { PyObjectRef , PyResult , VirtualMachine , function:: FuncArgs } ;
5+ use crate :: vm:: { PyResult , VirtualMachine , function:: FuncArgs } ;
66
77 #[ pyfunction]
88 fn collect ( _args : FuncArgs , _vm : & VirtualMachine ) -> i32 {
@@ -40,15 +40,13 @@ mod gc {
4040 }
4141
4242 #[ pyfunction]
43- fn get_referents ( _args : FuncArgs , vm : & VirtualMachine ) -> PyObjectRef {
44- // RustPython does not track object references.
45- vm. ctx . new_tuple ( vec ! [ ] ) . into ( )
43+ fn get_referents ( _args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
44+ Err ( vm. new_not_implemented_error ( "" ) )
4645 }
4746
4847 #[ pyfunction]
49- fn get_referrers ( _args : FuncArgs , vm : & VirtualMachine ) -> PyObjectRef {
50- // RustPython does not track object references.
51- vm. ctx . new_list ( vec ! [ ] ) . into ( )
48+ fn get_referrers ( _args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
49+ Err ( vm. new_not_implemented_error ( "" ) )
5250 }
5351
5452 #[ pyfunction]
Original file line number Diff line number Diff line change @@ -104,13 +104,8 @@ pub fn import_builtin(vm: &VirtualMachine, module_name: &str) -> PyResult {
104104 // Phase 1: Create module from definition
105105 let module = PyModule :: from_def ( def) . into_ref ( & vm. ctx ) ;
106106
107- // Initialize module dict
108- let dict = vm. ctx . new_dict ( ) ;
109- dict. set_item ( "__name__" , vm. ctx . new_str ( def. name . as_str ( ) ) . into ( ) , vm) ?;
110- if let Some ( doc) = def. doc {
111- dict. set_item ( "__doc__" , vm. ctx . new_str ( doc. as_str ( ) ) . into ( ) , vm) ?;
112- }
113- module. set_attr ( "__dict__" , dict, vm) ?;
107+ // Initialize module dict using proper method
108+ PyModule :: __init_dict_from_def ( vm, & module) ;
114109
115110 // Add to sys.modules BEFORE exec (critical for circular import handling)
116111 sys_modules. set_item ( module_name, module. clone ( ) . into ( ) , vm) ?;
Original file line number Diff line number Diff line change @@ -135,13 +135,8 @@ mod _imp {
135135 // Phase 1: Create module from definition
136136 let module = PyModule :: from_def ( def) . into_ref ( & vm. ctx ) ;
137137
138- // Initialize module dict
139- let dict = vm. ctx . new_dict ( ) ;
140- dict. set_item ( "__name__" , vm. ctx . new_str ( def. name . as_str ( ) ) . into ( ) , vm) ?;
141- if let Some ( doc) = def. doc {
142- dict. set_item ( "__doc__" , vm. ctx . new_str ( doc. as_str ( ) ) . into ( ) , vm) ?;
143- }
144- module. set_attr ( "__dict__" , dict, vm) ?;
138+ // Initialize module dict using proper method
139+ PyModule :: __init_dict_from_def ( vm, & module) ;
145140
146141 // Add to sys.modules BEFORE exec (critical for circular import handling)
147142 sys_modules. set_item ( & * name, module. clone ( ) . into ( ) , vm) ?;
Original file line number Diff line number Diff line change @@ -476,13 +476,15 @@ impl VirtualMachine {
476476 }
477477
478478 /// Can only be used in the initialization closure passed to [`Interpreter::with_init`]
479+ #[ deprecated( note = "use add_native_module_def(s) with multi-phase module initialization" ) ]
479480 pub fn add_native_module < S > ( & mut self , name : S , module : stdlib:: StdlibInitFunc )
480481 where
481482 S : Into < Cow < ' static , str > > ,
482483 {
483484 self . state_mut ( ) . module_inits . insert ( name. into ( ) , module) ;
484485 }
485486
487+ #[ deprecated( note = "use add_native_module_defs with multi-phase module initialization" ) ]
486488 pub fn add_native_modules < I > ( & mut self , iter : I )
487489 where
488490 I : IntoIterator < Item = ( Cow < ' static , str > , stdlib:: StdlibInitFunc ) > ,
You can’t perform that action at this time.
0 commit comments