py/builtinimport: Raise ValueError for bad relative import, per CPython.

This commit is contained in:
Damien George 2017-01-16 16:21:04 +11:00
parent 9317fee523
commit 63e291de70
2 changed files with 3 additions and 4 deletions

View File

@ -360,8 +360,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
qstr new_mod_q = qstr_from_strn(new_mod, new_mod_l);
DEBUG_printf("Resolved base name for relative import: '%s'\n", qstr_str(new_mod_q));
if (new_mod_q == MP_QSTR_) {
// CPython raises SystemError
mp_raise_msg(&mp_type_ImportError, "cannot perform relative import");
mp_raise_msg(&mp_type_ValueError, "cannot perform relative import");
}
module_name = MP_OBJ_NEW_QSTR(new_mod_q);
mod_str = new_mod;

View File

@ -7,5 +7,5 @@ print(bar)
# whereas CPython raises a ValueError
try:
from .... import mod1
except (ImportError, ValueError):
print('Error')
except ValueError:
print('ValueError')