From 671b35ceae2d2b7b64f755524b3a5a42e29abcfe Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 4 Jul 2023 11:43:14 +1000 Subject: [PATCH] py/builtinimport: Fix built-in imports when external import is disabled. Follow-up to 24c02c4eb5f11200f876bb57cd63a9d0bae91fd3 for when MICROPY_ENABLE_EXTERNAL_IMPORT=0. It now needs to try both extensible and non-extensible modules. Signed-off-by: Jim Mussared --- py/builtinimport.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/py/builtinimport.c b/py/builtinimport.c index 4fee04b8f341..d4cd254fd6a1 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -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