Skip to content

Commit ddf6765

Browse files
committed
Add sys.builtin_module_names
1 parent 0a1399a commit ddf6765

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

tests/snippets/sysmod.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
assert sys.argv[0].endswith('.py')
55

66
assert sys.platform == "linux" or sys.platform == "darwin" or sys.platform == "win32" or sys.platform == "unknown"
7+
8+
assert isinstance(sys.builtin_module_names, tuple)
9+
assert 'sys' in sys.builtin_module_names

vm/src/sysmodule.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{env, mem};
44
use crate::frame::FrameRef;
55
use crate::function::{OptionalArg, PyFuncArgs};
66
use crate::obj::objstr::PyStringRef;
7-
use crate::pyobject::{ItemProtocol, PyContext, PyObjectRef, PyResult};
7+
use crate::pyobject::{IntoPyObject, ItemProtocol, PyContext, PyObjectRef, PyResult};
88
use crate::vm::VirtualMachine;
99

1010
/*
@@ -144,9 +144,14 @@ setprofile() -- set the global profiling function
144144
setrecursionlimit() -- set the max recursion depth for the interpreter
145145
settrace() -- set the global debug tracing function
146146
";
147+
let mut module_names: Vec<_> = vm.stdlib_inits.borrow().keys().cloned().collect();
148+
module_names.push("sys".to_string());
149+
module_names.push("builtins".to_string());
150+
module_names.sort();
147151
let modules = ctx.new_dict();
148152
extend_module!(vm, module, {
149153
"argv" => argv(ctx),
154+
"builtin_module_names" => ctx.new_tuple(module_names.iter().map(|v| v.into_pyobject(vm).unwrap()).collect()),
150155
"getrefcount" => ctx.new_rustfunc(sys_getrefcount),
151156
"getsizeof" => ctx.new_rustfunc(sys_getsizeof),
152157
"intern" => ctx.new_rustfunc(sys_intern),

0 commit comments

Comments
 (0)