@@ -49,9 +49,6 @@ pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
49
49
} ;
50
50
let path = ctx. new_list ( path_list) ;
51
51
52
- let modules = ctx. new_dict ( ) ;
53
-
54
- let sys_name = "sys" ;
55
52
let sys_doc = "This module provides access to some objects used or maintained by the
56
53
interpreter and to functions that interact strongly with the interpreter.
57
54
@@ -121,20 +118,22 @@ setprofile() -- set the global profiling function
121
118
setrecursionlimit() -- set the max recursion depth for the interpreter
122
119
settrace() -- set the global debug tracing function
123
120
" ;
124
- let sys_mod = ctx. new_module ( & sys_name, ctx. new_scope ( None ) ) ;
121
+ let modules = ctx. new_dict ( ) ;
122
+ let sys_name = "sys" ;
123
+ let sys_mod = py_module ! ( ctx, sys_name, {
124
+ "argv" => argv( ctx) ,
125
+ "getrefcount" => ctx. new_rustfunc( sys_getrefcount) ,
126
+ "getsizeof" => ctx. new_rustfunc( sys_getsizeof) ,
127
+ "maxsize" => ctx. new_int( std:: usize :: MAX ) ,
128
+ "path" => path,
129
+ "ps1" => ctx. new_str( ">>>>> " . to_string( ) ) ,
130
+ "ps2" => ctx. new_str( "..... " . to_string( ) ) ,
131
+ "__doc__" => ctx. new_str( sys_doc. to_string( ) ) ,
132
+ "_getframe" => ctx. new_rustfunc( getframe) ,
133
+ } ) ;
125
134
126
135
ctx. set_item ( & modules, sys_name, sys_mod. clone ( ) ) ;
127
-
128
136
ctx. set_attr ( & sys_mod, "modules" , modules) ;
129
- ctx. set_attr ( & sys_mod, "argv" , argv ( ctx) ) ;
130
- ctx. set_attr ( & sys_mod, "getrefcount" , ctx. new_rustfunc ( sys_getrefcount) ) ;
131
- ctx. set_attr ( & sys_mod, "getsizeof" , ctx. new_rustfunc ( sys_getsizeof) ) ;
132
- ctx. set_attr ( & sys_mod, "maxsize" , ctx. new_int ( std:: usize:: MAX ) ) ;
133
- ctx. set_attr ( & sys_mod, "path" , path) ;
134
- ctx. set_attr ( & sys_mod, "ps1" , ctx. new_str ( ">>>>> " . to_string ( ) ) ) ;
135
- ctx. set_attr ( & sys_mod, "ps2" , ctx. new_str ( "..... " . to_string ( ) ) ) ;
136
- ctx. set_attr ( & sys_mod, "__doc__" , ctx. new_str ( sys_doc. to_string ( ) ) ) ;
137
- ctx. set_attr ( & sys_mod, "_getframe" , ctx. new_rustfunc ( getframe) ) ;
138
137
139
138
sys_mod
140
139
}
0 commit comments