Skip to content

Commit ad6178b

Browse files
committed
builtinimport: Fix broken namespace imports due to dup vstr_cut_tail_bytes().
1 parent f9589d2 commit ad6178b

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

py/builtinimport.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
287287
// create a qstr for the module name up to this depth
288288
qstr mod_name = qstr_from_strn(mod_str, i);
289289
DEBUG_printf("Processing module: %s\n", qstr_str(mod_name));
290+
DEBUG_printf("Previous path: %s\n", vstr_str(&path));
290291

291292
// find the file corresponding to the module name
292293
mp_import_stat_t stat;
@@ -299,6 +300,7 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
299300
vstr_add_strn(&path, mod_str + last, i - last);
300301
stat = stat_dir_or_file(&path);
301302
}
303+
DEBUG_printf("Current path: %s\n", vstr_str(&path));
302304

303305
// fail if we couldn't find the file
304306
if (stat == MP_IMPORT_STAT_NO_EXIST) {
@@ -323,8 +325,8 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
323325
printf("Notice: %s is imported as namespace package\n", vstr_str(&path));
324326
} else {
325327
do_load(module_obj, &path);
328+
vstr_cut_tail_bytes(&path, sizeof("/__init__.py") - 1); // cut off /__init__.py
326329
}
327-
vstr_cut_tail_bytes(&path, sizeof("/__init__.py") - 1); // cut off /__init__.py
328330
} else { // MP_IMPORT_STAT_FILE
329331
do_load(module_obj, &path);
330332
// TODO: We cannot just break here, at the very least, we must execute

0 commit comments

Comments
 (0)