8000 py/builtinimport: Fix bug when importing names from frozen packages. · boneskull/circuitpython@b528e9a · GitHub
[go: up one dir, main page]

Skip to content

Commit b528e9a

Browse files
committed
py/builtinimport: Fix bug when importing names from frozen packages.
The commit d9047d3 introduced a bug whereby "from a.b import c" stopped working for frozen packages. This is because the path was not properly truncated and became "a//b". Such a path resolves correctly for a "real" filesystem, but not for a search in the list of frozen modules.
1 parent b2611d6 commit b528e9a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

py/builtinimport.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,15 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
466466
// https://docs.python.org/3/reference/import.html
467467
// "Specifically, any module that contains a __path__ attribute is considered a package."
468468
mp_store_attr(module_obj, MP_QSTR___path__, mp_obj_new_str(vstr_str(&path), vstr_len(&path), false));
469+
size_t orig_path_len = path.len;
469470
vstr_add_char(&path, PATH_SEP_CHAR);
470471
vstr_add_str(&path, "__init__.py");
471472
if (stat_file_py_or_mpy(&path) != MP_IMPORT_STAT_FILE) {
472-
vstr_cut_tail_bytes(&path, sizeof("/__init__.py") - 1); // cut off /__init__.py
473473
//mp_warning("%s is imported as namespace package", vstr_str(&path));
474474
} else {
475475
do_load(module_obj, &path);
476-
vstr_cut_tail_bytes(&path, sizeof("/__init__.py") - 1); // cut off /__init__.py
477476
}
477+
path.len = orig_path_len;
478478
} else { // MP_IMPORT_STAT_FILE
479479
do_load(module_obj, &path);
480480
// TODO: We cannot just break here, at the very least, we must execute

0 commit comments

Comments
 (0)
0