@@ -150,25 +150,29 @@ public static void Initialize() {
150
150
IntPtr clr = Python . Runtime . ImportHook . GetCLRModule ( ) ;
151
151
IntPtr clr_dict = Runtime . PyModule_GetDict ( clr ) ;
152
152
153
- IntPtr globals = Runtime . PyEval_GetGlobals ( ) ;
154
153
PyDict locals = new PyDict ( ) ;
155
154
try
156
155
{
156
+ IntPtr module = Runtime . PyImport_AddModule ( "clr._extras" ) ;
157
+ IntPtr module_globals = Runtime . PyModule_GetDict ( module ) ;
157
158
IntPtr builtins = Runtime . PyEval_GetBuiltins ( ) ;
158
- Runtime . PyDict_SetItemString ( locals . Handle , "__builtins__" , builtins ) ;
159
+ Runtime . PyDict_SetItemString ( module_globals , "__builtins__" , builtins ) ;
159
160
160
161
var assembly = Assembly . GetExecutingAssembly ( ) ;
161
162
using ( Stream stream = assembly . GetManifestResourceStream ( "Python.Runtime.resources.clr.py" ) )
162
163
using ( StreamReader reader = new StreamReader ( stream ) )
163
164
{
164
165
// add the contents of clr.py to the module
165
166
string clr_py = reader . ReadToEnd ( ) ;
166
- PyObject result = RunString ( clr_py , globals , locals . Handle ) ;
167
+ PyObject result = RunString ( clr_py , module_globals , locals . Handle ) ;
167
168
if ( null == result )
168
169
throw new PythonException ( ) ;
169
170
result . Dispose ( ) ;
170
171
}
171
172
173
+ // add the imported module to the clr module, and copy the API functions
174
+ // and decorators into the main clr module.
175
+ Runtime . PyDict_SetItemString ( clr_dict , "_extras" , module ) ;
172
176
foreach ( PyObject key in locals . Keys ( ) )
173
177
{
174
178
if ( ! key . ToString ( ) . StartsWith ( "_" ) ) {
0 commit comments