Skip to content

Commit e8d8474

Browse files
Set stdio to None if feature is disabled
More in line with what CPython does
1 parent 84bdd8d commit e8d8474

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

vm/src/vm/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::{
1919
code::PyCode,
2020
pystr::AsPyStr,
2121
tuple::{PyTuple, PyTupleTyped},
22-
PyBaseExceptionRef, PyDictRef, PyInt, PyList, PyModule, PyStr, PyStrInterned, PyStrRef,
23-
PyTypeRef,
22+
PyBaseExceptionRef, PyDictRef, PyInt, PyList, PyModule, PyNone, PyStr, PyStrInterned,
23+
PyStrRef, PyTypeRef,
2424
},
2525
codecs::CodecsRegistry,
2626
common::{hash::HashSecret, lock::PyMutex, rc::PyRc},
@@ -329,6 +329,16 @@ impl VirtualMachine {
329329
set_stdio("stderr", 2, "w")?;
330330
}
331331

332+
#[cfg(not(feature = "stdio"))]
333+
{
334+
self.sys_module
335+
.set_attr("stdin", PyNone.into_pyobject(self), self)?;
336+
self.sys_module
337+
.set_attr("stdout", PyNone.into_pyobject(self), self)?;
338+
self.sys_module
339+
.set_attr("stderr", PyNone.into_pyobject(self), self)?;
340+
}
341+
332342
let io_open = io.get_attr("open", self)?;
333343
self.builtins.set_attr("open", io_open, self)?;
334344
}

0 commit comments

Comments
 (0)