Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb528e9a

Browse files
committed
py/builtinimport: Fix bug when importing names from frozen packages.
The commitd9047d3 introduced a bugwhereby "from a.b import c" stopped working for frozen packages. This isbecause the path was not properly truncated and became "a//b". Such apath resolves correctly for a "real" filesystem, but not for a search inthe list of frozen modules.
1 parentb2611d6 commitb528e9a

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_torig_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)

[8]ページ先頭

©2009-2025 Movatter.jp