Skip to content

Commit 63e291d

Browse files
committed
py/builtinimport: Raise ValueError for bad relative import, per CPython.
1 parent 9317fee commit 63e291d

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

py/builtinimport.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
360360
qstr new_mod_q = qstr_from_strn(new_mod, new_mod_l);
361361
DEBUG_printf("Resolved base name for relative import: '%s'\n", qstr_str(new_mod_q));
362362
if (new_mod_q == MP_QSTR_) {
363-
// CPython raises SystemError
364-
mp_raise_msg(&mp_type_ImportError, "cannot perform relative import");
363+
mp_raise_msg(&mp_type_ValueError, "cannot perform relative import");
365364
}
366365
module_name = MP_OBJ_NEW_QSTR(new_mod_q);
367366
mod_str = new_mod;

tests/import/pkg7/subpkg1/subpkg2/mod3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
# whereas CPython raises a ValueError
88
try:
99
from .... import mod1
10-
except (ImportError, ValueError):
11-
print('Error')
10+
except ValueError:
11+
print('ValueError')

0 commit comments

Comments
 (0)