Skip to content

Commit 8452dbe

Browse files
authored
Merge pull request RustPython#1942 from RustPython/coolreader18/init-with-_io
Initialize the vm with imports from _io instead of io
2 parents 802913b + 3b29fb7 commit 8452dbe

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

vm/src/vm.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ impl VirtualMachine {
250250

251251
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
252252
{
253-
let io = self.import("io", &[], 0)?;
253+
// this isn't fully compatible with CPython; it imports "io" and sets
254+
// builtins.open to io.OpenWrapper, but this is easier, since it doesn't
255+
// require the Python stdlib to be present
256+
let io = self.import("_io", &[], 0)?;
254257
let io_open = self.get_attribute(io.clone(), "open")?;
255258
let set_stdio = |name, fd, mode: &str| {
256259
let stdio = self.invoke(
@@ -269,8 +272,7 @@ impl VirtualMachine {
269272
set_stdio("stdout", 1, "w")?;
270273
set_stdio("stderr", 2, "w")?;
271274

272-
let open_wrapper = self.get_attribute(io, "OpenWrapper")?;
273-
self.set_attr(&self.builtins, "open", open_wrapper)?;
275+
self.set_attr(&self.builtins, "open", io_open)?;
274276
}
275277

276278
Ok(())

0 commit comments

Comments
 (0)