py: Factor out mp_obj_is_package() function.
This commit is contained in:
parent
8becca7c82
commit
e5a3759ff5
@ -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));
|
||||
|
2
py/obj.h
2
py/obj.h
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user