@@ -10,7 +10,7 @@ use std::path::PathBuf;
10
10
11
11
use self :: rustpython_parser:: parser;
12
12
use super :: compile;
13
- use super :: pyobject:: { DictProtocol , PyObject , PyObjectKind , PyResult } ;
13
+ use super :: pyobject:: { DictProtocol , PyObjectKind , PyResult } ;
14
14
use super :: vm:: VirtualMachine ;
15
15
16
16
fn import_module ( vm : & mut VirtualMachine , module : & String ) -> PyResult {
@@ -50,28 +50,23 @@ fn import_module(vm: &mut VirtualMachine, module: &String) -> PyResult {
50
50
} ;
51
51
52
52
let builtins = vm. get_builtin_scope ( ) ;
53
- let scope = vm. context ( ) . new_scope ( Some ( builtins) ) ;
53
+ let scope = vm. ctx . new_scope ( Some ( builtins) ) ;
54
54
55
55
match vm. run_code_obj ( code_obj, scope. clone ( ) ) {
56
56
Ok ( _) => { }
57
57
Err ( value) => return Err ( value) ,
58
58
}
59
- Ok ( scope)
59
+ let py_module = vm. ctx . new_module ( module, scope) ;
60
+ Ok ( py_module)
60
61
}
61
62
62
- pub fn import ( vm : & mut VirtualMachine , module : & String , symbol : & Option < String > ) -> PyResult {
63
- let scope = import_module ( vm, module ) ?;
63
+ pub fn import ( vm : & mut VirtualMachine , module_name : & String , symbol : & Option < String > ) -> PyResult {
64
+ let module = import_module ( vm, module_name ) ?;
64
65
// If we're importing a symbol, look it up and use it, otherwise construct a module and return
65
66
// that
66
67
let obj = match symbol {
67
- Some ( symbol) => scope. get_item ( symbol) . unwrap ( ) ,
68
- None => PyObject :: new (
69
- PyObjectKind :: Module {
70
- name : module. clone ( ) ,
71
- dict : scope. clone ( ) ,
72
- } ,
73
- vm. get_type ( ) ,
74
- ) ,
68
+ Some ( symbol) => module. get_item ( symbol) . unwrap ( ) ,
69
+ None => module,
75
70
} ;
76
71
Ok ( obj)
77
72
}
0 commit comments