From 3b29fb72652596ef44e6d05c73078d08471b0859 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Sun, 24 May 2020 21:08:51 -0500 Subject: [PATCH] Initialize the vm with imports from _io instead of io --- vm/src/vm.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 6e41436cc4..915ba9c80d 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -245,7 +245,10 @@ impl VirtualMachine { #[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))] { - let io = self.import("io", &[], 0)?; + // this isn't fully compatible with CPython; it imports "io" and sets + // builtins.open to io.OpenWrapper, but this is easier, since it doesn't + // require the Python stdlib to be present + let io = self.import("_io", &[], 0)?; let io_open = self.get_attribute(io.clone(), "open")?; let set_stdio = |name, fd, mode: &str| { let stdio = self.invoke( @@ -264,8 +267,7 @@ impl VirtualMachine { set_stdio("stdout", 1, "w")?; set_stdio("stderr", 2, "w")?; - let open_wrapper = self.get_attribute(io, "OpenWrapper")?; - self.set_attr(&self.builtins, "open", open_wrapper)?; + self.set_attr(&self.builtins, "open", io_open)?; } Ok(())