Commit c4045f57 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

builtinimport: Catch case when relative import happens without active package.

CPython raises SystemError in this case, but we don't have that enabled, so
raise ImportError.
parent 6557a096
......@@ -238,7 +238,11 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, const mp_obj_t *args) {
qstr new_mod_q = qstr_from_strn(new_mod, new_mod_l);
DEBUG_printf("Resolved relative name: %s\n", qstr_str(new_mod_q));
DEBUG_printf("Resolved base name for relative import: '%s'\n", qstr_str(new_mod_q));
if (new_mod_q == MP_QSTR_) {
// CPython raises SystemError
nlr_raise(mp_obj_new_exception_msg(&mp_type_ImportError, "cannot perform relative import"));
module_name = MP_OBJ_NEW_QSTR(new_mod_q);
mod_str = new_mod;
mod_len = new_mod_l;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment