summaryrefslogtreecommitdiffstatshomepage
path: root/py/objmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/objmodule.c')
-rw-r--r--py/objmodule.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/py/objmodule.c b/py/objmodule.c
index fa64736f7f..01349c3d28 100644
--- a/py/objmodule.c
+++ b/py/objmodule.c
@@ -40,7 +40,19 @@ STATIC mp_map_t mp_loaded_modules_map; // TODO: expose as sys.modules
STATIC void module_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
mp_obj_module_t *self = self_in;
- print(env, "<module '%s' from '-unknown-file-'>", qstr_str(self->name));
+ const char *name = qstr_str(self->name);
+
+#if MICROPY_PY___FILE__
+ // If we store __file__ to imported modules then try to lookup this
+ // symbol to give more information about the module.
+ mp_map_elem_t *elem = mp_map_lookup(&self->globals->map, MP_OBJ_NEW_QSTR(MP_QSTR___file__), MP_MAP_LOOKUP);
+ if (elem != NULL) {
+ print(env, "<module '%s' from '%s'>", name, mp_obj_str_get_str(elem->value));
+ return;
+ }
+#endif
+
+ print(env, "<module '%s'>", name);
}
STATIC void module_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {