@@ -400,21 +400,31 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
400400 DEBUG_printf ("Current path: %.*s\n" , vstr_len (& path ), vstr_str (& path ));
401401
402402 if (stat == MP_IMPORT_STAT_NO_EXIST ) {
403- #if MICROPY_MODULE_WEAK_LINKS
404- // check if there is a weak link to this module
405- if (i == mod_len ) {
406- mp_map_elem_t * el = mp_map_lookup ((mp_map_t * )& mp_builtin_module_weak_links_map , MP_OBJ_NEW_QSTR (mod_name ), MP_MAP_LOOKUP );
403+ // This is just the module name after the previous .
404+ qstr current_module_name = qstr_from_strn (mod_str + last , i - last );
405+ mp_map_elem_t * el = NULL ;
406+ if (outer_module_obj == MP_OBJ_NULL ) {
407+ el = mp_map_lookup ((mp_map_t * )& mp_builtin_module_map ,
408+ MP_OBJ_NEW_QSTR (current_module_name ),
409+ MP_MAP_LOOKUP );
410+ #if MICROPY_MODULE_WEAK_LINKS
411+ // check if there is a weak link to this module
407412 if (el == NULL ) {
408- goto no_exist ;
413+ el = mp_map_lookup ((mp_map_t * )& mp_builtin_module_weak_links_map ,
414+ MP_OBJ_NEW_QSTR (current_module_name ),
415+ MP_MAP_LOOKUP );
409416 }
410- // found weak linked module
417+ #endif
418+ } else {
419+ el = mp_map_lookup (& ((mp_obj_module_t * ) outer_module_obj )-> globals -> map ,
420+ MP_OBJ_NEW_QSTR (current_module_name ),
421+ MP_MAP_LOOKUP );
422+ }
423+
424+ if (el != NULL && MP_OBJ_IS_TYPE (el -> value , & mp_type_module )) {
411425 module_obj = el -> value ;
412426 mp_module_call_init (mod_name , module_obj );
413427 } else {
414- no_exist :
415- #else
416- {
417- #endif
418428 // couldn't find the file, so fail
419429 if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
420430 mp_raise_ImportError (translate ("module not found" ));
0 commit comments