Skip to content

Commit 301ba81

Browse files
dpgeorgepfalcon
authored andcommitted
py/builtinimport: Change relative import's ValueError to ImportError.
Following CPython change, see https://bugs.python.org/issue37444. Signed-off-by: Damien George <[email protected]>
1 parent 6d226d6 commit 301ba81

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

py/builtinimport.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
359359

360360
// We must have some component left over to import from
361361
if (p == this_name) {
362-
mp_raise_ValueError(MP_ERROR_TEXT("can't perform relative import"));
362+
mp_raise_msg(&mp_type_ImportError, MP_ERROR_TEXT("can't perform relative import"));
363363
}
364364

365365
uint new_mod_l = (mod_len == 0 ? (size_t)(p - this_name) : (size_t)(p - this_name) + 1 + mod_len);

tests/import/import_pkg7.py.exp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pkg __name__: pkg7
2+
pkg __name__: pkg7.subpkg1
3+
pkg __name__: pkg7.subpkg1.subpkg2
4+
mod1
5+
mod2
6+
mod1.foo
7+
mod2.bar
8+
ImportError

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
# attempted relative import beyond top-level package
88
try:
99
from .... import mod1
10-
except ValueError:
11-
print("ValueError")
10+
except ImportError:
11+
print("ImportError")

0 commit comments

Comments
 (0)