Skip to content

Commit 5b534ad

Browse files
Merge pull request RustPython#1091 from palaviv/fix-import
Fix locals and globals in call to __import__
2 parents 36adf45 + 49f3bf7 commit 5b534ad

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

vm/src/vm.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,20 @@ impl VirtualMachine {
309309
.get_attribute(self.builtins.clone(), "__import__")
310310
.map_err(|_| self.new_import_error("__import__ not found".to_string()))?;
311311

312-
let locals = if let Some(frame) = self.current_frame() {
313-
frame.scope.get_locals().into_object()
312+
let (locals, globals) = if let Some(frame) = self.current_frame() {
313+
(
314+
frame.scope.get_locals().into_object(),
315+
frame.scope.globals.clone().into_object(),
316+
)
314317
} else {
315-
self.get_none()
318+
(self.get_none(), self.get_none())
316319
};
317320
self.invoke(
318321
import_func,
319322
vec![
320323
self.ctx.new_str(module.to_string()),
324+
globals,
321325
locals,
322-
self.get_none(),
323326
from_list.clone(),
324327
self.ctx.new_int(level),
325328
],

0 commit comments

Comments
 (0)