Skip to content

Commit 599bbc1

Browse files
committed
py: from import * should not import symbols starting with underscore.
I skipped implementing this initially, but then it causes __name__ of current module be overwritten and relative imports fail.
1 parent 5b65f0c commit 599bbc1

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

py/runtime.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,10 +1060,14 @@ mp_obj_t mp_import_from(mp_obj_t module, qstr name) {
10601060
void mp_import_all(mp_obj_t module) {
10611061
DEBUG_printf("import all %p\n", module);
10621062

1063+
// TODO: Support __all__
10631064
mp_map_t *map = mp_obj_dict_get_map(mp_obj_module_get_globals(module));
10641065
for (uint i = 0; i < map->alloc; i++) {
10651066
if (MP_MAP_SLOT_IS_FILLED(map, i)) {
1066-
mp_store_name(MP_OBJ_QSTR_VALUE(map->table[i].key), map->table[i].value);
1067+
qstr name = MP_OBJ_QSTR_VALUE(map->table[i].key);
1068+
if (*qstr_str(name) != '_') {
1069+
mp_store_name(name, map->table[i].value);
1070+
}
10671071
}
10681072
}
10691073
}

0 commit comments

Comments
 (0)