Skip to content

Commit da7745c

Browse files
committed
Fix module type
1 parent ac3c18c commit da7745c

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

tests/snippets/ast_snippet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import ast
3+
print(ast)
34

45
source = """
56
def foo():

vm/src/import.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::path::PathBuf;
1010

1111
use self::rustpython_parser::parser;
1212
use super::compile;
13-
use super::pyobject::{DictProtocol, PyObject, PyObjectKind, PyResult};
13+
use super::pyobject::{DictProtocol, PyObjectKind, PyResult};
1414
use super::vm::VirtualMachine;
1515

1616
fn import_module(vm: &mut VirtualMachine, module: &String) -> PyResult {
@@ -50,28 +50,23 @@ fn import_module(vm: &mut VirtualMachine, module: &String) -> PyResult {
5050
};
5151

5252
let builtins = vm.get_builtin_scope();
53-
let scope = vm.context().new_scope(Some(builtins));
53+
let scope = vm.ctx.new_scope(Some(builtins));
5454

5555
match vm.run_code_obj(code_obj, scope.clone()) {
5656
Ok(_) => {}
5757
Err(value) => return Err(value),
5858
}
59-
Ok(scope)
59+
let py_module = vm.ctx.new_module(module, scope);
60+
Ok(py_module)
6061
}
6162

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)?;
6465
// If we're importing a symbol, look it up and use it, otherwise construct a module and return
6566
// that
6667
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,
7570
};
7671
Ok(obj)
7772
}

vm/src/stdlib/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn program_to_ast(ctx: &PyContext, program: &ast::Program) -> PyObjectRef {
4444
}
4545

4646
// Create a node class instance
47-
fn create_node(ctx: &PyContext, name: &str) -> PyObjectRef {
47+
fn create_node(ctx: &PyContext, _name: &str) -> PyObjectRef {
4848
// TODO: instantiate a class of type given by name
4949
// TODO: lookup in the current module?
5050
let node = ctx.new_object();
@@ -152,8 +152,8 @@ fn statement_to_ast(ctx: &PyContext, statement: &ast::LocatedStatement) -> PyObj
152152
node
153153
}
154154
ast::Statement::For {
155-
target,
156-
iter,
155+
target: _,
156+
iter: _,
157157
body,
158158
orelse,
159159
} => {

0 commit comments

Comments
 (0)