Skip to content

Commit

Permalink
py/builtinimport: Fix built-in imports when external import is disabled.
Browse files Browse the repository at this point in the history
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 <jim.mussared@gmail.com>
  • Loading branch information
jimmo authored and dpgeorge committed Jul 13, 2023
1 parent 606ec9b commit 671b35c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion py/builtinimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,17 @@ mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args) {
return elem->value;
}

// Try the name directly as a built-in.
// Try the name directly as a non-extensible built-in (e.g. `micropython`).
qstr module_name_qstr = mp_obj_str_get_qstr(args[0]);
mp_obj_t module_obj = mp_module_get_builtin(module_name_qstr, false);
if (module_obj != MP_OBJ_NULL) {
return module_obj;
}
// Now try as an extensible built-in (e.g. `time`).
module_obj = mp_module_get_builtin(module_name_qstr, true);
if (module_obj != MP_OBJ_NULL) {
return module_obj;
}

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

0 comments on commit 671b35c

Please sign in to comment.