From 599bbc111cbd83329e9418cefd1ed62ca2ed984c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 18 Apr 2014 04:11:19 +0300 Subject: [PATCH] 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. --- py/runtime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/py/runtime.c b/py/runtime.c index 7830301c77..30db01cd53 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1060,10 +1060,14 @@ import_error: void mp_import_all(mp_obj_t module) { DEBUG_printf("import all %p\n", module); + // TODO: Support __all__ mp_map_t *map = mp_obj_dict_get_map(mp_obj_module_get_globals(module)); for (uint i = 0; i < map->alloc; i++) { if (MP_MAP_SLOT_IS_FILLED(map, i)) { - mp_store_name(MP_OBJ_QSTR_VALUE(map->table[i].key), map->table[i].value); + qstr name = MP_OBJ_QSTR_VALUE(map->table[i].key); + if (*qstr_str(name) != '_') { + mp_store_name(name, map->table[i].value); + } } } }