Skip to content

Commit 671b35c

Browse files
jimmodpgeorge
authored andcommitted
py/builtinimport: Fix built-in imports when external import is disabled.
Follow-up to 24c02c4 for when MICROPY_ENABLE_EXTERNAL_IMPORT=0. It now needs to try both extensible and non-extensible modules. Signed-off-by: Jim Mussared <[email protected]>
1 parent 606ec9b commit 671b35c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

py/builtinimport.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,17 @@ mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args) {
632632
return elem->value;
633633
}
634634

635-
// Try the name directly as a built-in.
635+
// Try the name directly as a non-extensible built-in (e.g. `micropython`).
636636
qstr module_name_qstr = mp_obj_str_get_qstr(args[0]);
637637
mp_obj_t module_obj = mp_module_get_builtin(module_name_qstr, false);
638638
if (module_obj != MP_OBJ_NULL) {
639639
return module_obj;
640640
}
641+
// Now try as an extensible built-in (e.g. `time`).
642+
module_obj = mp_module_get_builtin(module_name_qstr, true);
643+
if (module_obj != MP_OBJ_NULL) {
644+
return module_obj;
645+
}
641646

642647
// Couldn't find the module, so fail
643648
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE

0 commit comments

Comments
 (0)