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>
This commit is contained in:
parent
c3199f5649
commit
53519e322a
|
@ -313,7 +313,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
|
||||||
|
|
||||||
// We must have some component left over to import from
|
// We must have some component left over to import from
|
||||||
if (p == this_name) {
|
if (p == this_name) {
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("can't perform relative import"));
|
mp_raise_msg(&mp_type_ImportError, MP_ERROR_TEXT("can't perform relative import"));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint new_mod_l = (mod_len == 0 ? (size_t)(p - this_name) : (size_t)(p - this_name) + 1 + mod_len);
|
uint new_mod_l = (mod_len == 0 ? (size_t)(p - this_name) : (size_t)(p - this_name) + 1 + mod_len);
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
pkg __name__: pkg7
|
||||||
|
pkg __name__: pkg7.subpkg1
|
||||||
|
pkg __name__: pkg7.subpkg1.subpkg2
|
||||||
|
mod1
|
||||||
|
mod2
|
||||||
|
mod1.foo
|
||||||
|
mod2.bar
|
||||||
|
ImportError
|
|
@ -7,5 +7,5 @@ print(bar)
|
||||||
# attempted relative import beyond top-level package
|
# attempted relative import beyond top-level package
|
||||||
try:
|
try:
|
||||||
from .... import mod1
|
from .... import mod1
|
||||||
except ValueError:
|
except ImportError:
|
||||||
print("ValueError")
|
print("ImportError")
|
||||||
|
|
Loading…
Reference in New Issue