8000 builtinimport: add the module specified by -m to sys.modules as '__ma… · sparkfun/circuitpython@21c719b · GitHub
[go: up one dir, main page]

Skip to content

Commit 21c719b

Browse files
dxxbpfalcon
authored andcommitted
builtinimport: add the module specified by -m to sys.modules as '__main__'
1 parent 34e0198 commit 21c719b

File tree

1 file changed

+2
-< 8000 !-- -->0
lines changed

1 file changed

+2
-0
lines changed

py/builtinimport.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
448448
mp_obj_module_t *o = MP_OBJ_TO_PTR(module_obj);
449449
mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__));
450450
#if MICROPY_CPYTHON_COMPAT
451+
// Store module as "__main__" in the dictionary of loaded modules (returned by sys.modules).
452+
mp_obj_dict_store(&MP_STATE_VM(mp_loaded_modules_dict), MP_OBJ_NEW_QSTR(MP_QSTR___main__), module_obj);
451453
// Store real name in "__main__" attribute. Choosen semi-randonly, to reuse existing qstr's.
452454
mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___main__), MP_OBJ_NEW_QSTR(mod_name));
453455
#endif

0 commit comments

Comments
 (0)
0