diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-06-27 00:34:53 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-06-27 00:40:21 +0300 |
commit | c4045f57e32a3e276999ceb28e966dbdb71a1e06 (patch) | |
tree | 2e58c9f7f971d54e3cdf1829deff9a22d9fe6850 /py | |
parent | 6557a096d6ee3c0d169617b9bcea5778246232b0 (diff) | |
download | micropython-c4045f57e32a3e276999ceb28e966dbdb71a1e06.tar.gz micropython-c4045f57e32a3e276999ceb28e966dbdb71a1e06.zip |
builtinimport: Catch case when relative import happens without active package.
CPython raises SystemError in this case, but we don't have that enabled, so
raise ImportError.
Diffstat (limited to 'py')
-rw-r--r-- | py/builtinimport.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c index aa8a8973c5..04b9d626d4 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -238,7 +238,11 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, const mp_obj_t *args) { } qstr new_mod_q = qstr_from_strn(new_mod, new_mod_l); - DEBUG_printf("Resolved relative name: %s\n", qstr_str(new_mod_q)); + DEBUG_printf("Resolved base name for relative import: '%s'\n", qstr_str(new_mod_q)); + if (new_mod_q == MP_QSTR_) { + // CPython raises SystemError + nlr_raise(mp_obj_new_exception_msg(&mp_type_ImportError, "cannot perform relative import")); + } module_name = MP_OBJ_NEW_QSTR(new_mod_q); mod_str = new_mod; mod_len = new_mod_l; |