diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2023-07-04 11:43:14 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-07-13 14:56:33 +1000 |
commit | 671b35ceae2d2b7b64f755524b3a5a42e29abcfe (patch) | |
tree | 2ff276c9c0b001646faa6de01d6e00f7c963cd7c /py/builtinimport.c | |
parent | 606ec9bfb1cca262cf5b936db78924a609f9e73d (diff) |
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 <jim.mussared@gmail.com>
Diffstat (limited to 'py/builtinimport.c')
-rw-r--r-- | py/builtinimport.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c index 4fee04b8f..d4cd254fd 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 |