summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-05-30 19:25:53 +1000
committerDamien George <damien@micropython.org>2021-05-30 19:35:03 +1000
commit53519e322a5a0bb395676cdaa132f5e82de22909 (patch)
treeea718dbfd5e1142f2a99683d9f8c3738f0d27fa6
parentc3199f56494429ba44f7e722597945dc91f3589c (diff)
downloadmicropython-53519e322a5a0bb395676cdaa132f5e82de22909.tar.gz
micropython-53519e322a5a0bb395676cdaa132f5e82de22909.zip
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>
-rw-r--r--py/builtinimport.c2
-rw-r--r--tests/import/import_pkg7.py.exp8
-rw-r--r--tests/import/pkg7/subpkg1/subpkg2/mod3.py4
3 files changed, 11 insertions, 3 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c
index 874d2dd7f0..abbeefced5 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -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
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);
diff --git a/tests/import/import_pkg7.py.exp b/tests/import/import_pkg7.py.exp
new file mode 100644
index 0000000000..8f21a615f6
--- /dev/null
+++ b/tests/import/import_pkg7.py.exp
@@ -0,0 +1,8 @@
+pkg __name__: pkg7
+pkg __name__: pkg7.subpkg1
+pkg __name__: pkg7.subpkg1.subpkg2
+mod1
+mod2
+mod1.foo
+mod2.bar
+ImportError
diff --git a/tests/import/pkg7/subpkg1/subpkg2/mod3.py b/tests/import/pkg7/subpkg1/subpkg2/mod3.py
index 0aa916d208..b0f4279fcf 100644
--- a/tests/import/pkg7/subpkg1/subpkg2/mod3.py
+++ b/tests/import/pkg7/subpkg1/subpkg2/mod3.py
@@ -7,5 +7,5 @@ print(bar)
# attempted relative import beyond top-level package
try:
from .... import mod1
-except ValueError:
- print("ValueError")
+except ImportError:
+ print("ImportError")