mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Merge pull request #955 from youknowone/sys-builtin_module_names
Add sys.builtin_module_names
This commit is contained in:
2 files changed
+9
-1
No files matched your search
@@ -4,3 +4,6 @@ print(sys.argv)
|
||||
assert sys.argv[0].endswith('.py')
|
||||
|
||||
assert sys.platform == "linux" or sys.platform == "darwin" or sys.platform == "win32" or sys.platform == "unknown"
|
||||
|
||||
assert isinstance(sys.builtin_module_names, tuple)
|
||||
assert 'sys' in sys.builtin_module_names
|
||||
+6
-1
@@ -4,7 +4,7 @@ use std::{env, mem};
|
||||
use crate::frame::FrameRef;
|
||||
use crate::function::{OptionalArg, PyFuncArgs};
|
||||
use crate::obj::objstr::PyStringRef;
|
||||
use crate::pyobject::{ItemProtocol, PyContext, PyObjectRef, PyResult};
|
||||
use crate::pyobject::{IntoPyObject, ItemProtocol, PyContext, PyObjectRef, PyResult};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
/*
|
||||
@@ -144,9 +144,14 @@ setprofile() -- set the global profiling function
|
||||
setrecursionlimit() -- set the max recursion depth for the interpreter
|
||||
settrace() -- set the global debug tracing function
|
||||
";
|
||||
let mut module_names: Vec<_> = vm.stdlib_inits.borrow().keys().cloned().collect();
|
||||
module_names.push("sys".to_string());
|
||||
module_names.push("builtins".to_string());
|
||||
module_names.sort();
|
||||
let modules = ctx.new_dict();
|
||||
extend_module!(vm, module, {
|
||||
"argv" => argv(ctx),
|
||||
"builtin_module_names" => ctx.new_tuple(module_names.iter().map(|v| v.into_pyobject(vm).unwrap()).collect()),
|
||||
"getrefcount" => ctx.new_rustfunc(sys_getrefcount),
|
||||
"getsizeof" => ctx.new_rustfunc(sys_getsizeof),
|
||||
"intern" => ctx.new_rustfunc(sys_intern),
|
||||
|
||||
Reference in new issue
Block a user