diff options
Diffstat (limited to 'py')
-rw-r--r-- | py/builtinimport.c | 6 | ||||
-rw-r--r-- | py/obj.h | 2 | ||||
-rw-r--r-- | py/runtime.c | 3 |
3 files changed, 9 insertions, 2 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c index 0eaa250036..80c4c77f68 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -55,6 +55,12 @@ #define PATH_SEP_CHAR '/' +bool mp_obj_is_package(mp_obj_t module) { + mp_obj_t dest[2]; + mp_load_method_maybe(module, MP_QSTR___path__, dest); + return dest[0] != MP_OBJ_NULL; +} + STATIC mp_import_stat_t stat_dir_or_file(vstr_t *path) { //printf("stat %s\n", vstr_str(path)); mp_import_stat_t stat = mp_import_stat(vstr_str(path)); @@ -555,6 +555,8 @@ typedef struct _mp_obj_module_t { mp_obj_dict_t *globals; } mp_obj_module_t; mp_obj_dict_t *mp_obj_module_get_globals(mp_obj_t self_in); +// check if given module object is a package +bool mp_obj_is_package(mp_obj_t module); // staticmethod and classmethod types; defined here so we can make const versions // this structure is used for instances of both staticmethod and classmethod diff --git a/py/runtime.c b/py/runtime.c index 8acd099804..f701e0a8d9 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1098,8 +1098,7 @@ import_error: } // See if it's a package, then can try FS import - mp_load_method_maybe(module, MP_QSTR___path__, dest); - if (dest[0] == MP_OBJ_NULL) { + if (!mp_obj_is_package(module)) { goto import_error; } |