From cb0ca5cd61a58b7ceab0c19f879d58c046346d27 Mon Sep 17 00:00:00 2001 From: rmliddle Date: Wed, 10 Oct 2018 22:18:19 +1100 Subject: [PATCH] set __name__ on import --- vm/src/import.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vm/src/import.rs b/vm/src/import.rs index 534959fe3..e70cdb662 100644 --- a/vm/src/import.rs +++ b/vm/src/import.rs @@ -45,7 +45,7 @@ fn import_uncached_module(vm: &mut VirtualMachine, module: &str) -> PyResult { let builtins = vm.get_builtin_scope(); let scope = vm.ctx.new_scope(Some(builtins)); - + scope.set_item(&"__name__".to_string(), vm.new_str(module.to_string())); match vm.run_code_obj(code_obj, scope.clone()) { Ok(_) => {} Err(value) => return Err(value), @@ -83,7 +83,8 @@ fn find_source(vm: &VirtualMachine, name: &str) -> io::Result { .filter_map(|item| match item.borrow().kind { PyObjectKind::String { ref value } => Some(PathBuf::from(value)), _ => None, - }).collect(), + }) + .collect(), _ => panic!("sys.path unexpectedly not a list"), };