8000 py/builtinimport: Change relative import's ValueError to ImportError. · micropython/micropython@53519e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 53519e3

Browse files
committed
py/builtinimport: Change relative import's ValueError to ImportError.
Following CPython change, see https://bugs.python.org/issue37444. Signed-off-by: Damien George <damien@micropython.org>
1 parent c3199f5 commit 53519e3

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

py/builtinimport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
313313

314314
// We must have some component left over to import from
315315
if (p == this_name) {
316-
mp_raise_ValueError(MP_ERROR_TEXT("can't perform relative import"));
316+
mp_raise_msg(&mp_type_ImportError, MP_ERROR_TEXT("can't perform relative import"));
317317
}
318318

319319
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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)
0