py/runtime: Look up __import__ in builtins if they can be overriden.
@@ -1357,7 +1357,16 @@ mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level) {
args[3] = fromlist;
args[4] = level;
- // TODO lookup __import__ and call that instead of going straight to builtin implementation
+ #if MICROPY_CAN_OVERRIDE_BUILTINS
+ if (MP_STATE_VM(mp_module_builtins_override_dict) != NULL) {
+ // lookup in additional dynamic table of builtins first
+ mp_map_elem_t *elem = mp_map_lookup(&MP_STATE_VM(mp_module_builtins_override_dict)->map, MP_OBJ_NEW_QSTR(MP_QSTR___import__), MP_MAP_LOOKUP);
+ if (elem != NULL) {
+ return mp_call_function_n_kw(elem->value, 5, 0, args);
+ }
+ }
+ #endif
+
return mp_builtin___import__(5, args);
}
