summaryrefslogtreecommitdiff
path: root/py/builtinimport.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-11 23:25:35 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-12 00:39:55 +0300
commit13d52df4c54cc6360a5c9c0bdbf7a3abb45c22d0 (patch)
tree4bf9c4c967393f6ea6917ef007074c686ca084dc /py/builtinimport.c
parente0813290980deeefd6a104193aece6b944945f0c (diff)
builtinimport: Set __path__ attribute on packages.
Per https://docs.python.org/3.3/reference/import.html , this is the way to tell module from package: "Specifically, any module that contains a __path__ attribute is considered a package." And it for sure will be needed to implement relative imports.
Diffstat (limited to 'py/builtinimport.c')
-rw-r--r--py/builtinimport.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c
index f7c5e4a1e..501ced764 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -228,6 +228,9 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
}
do_load(module_obj, &path);
vstr_cut_tail_bytes(&path, sizeof("/__init__.py") - 1); // cut off /__init__.py
+ // https://docs.python.org/3.3/reference/import.html
+ // "Specifically, any module that contains a __path__ attribute is considered a package."
+ mp_store_attr(module_obj, MP_QSTR___path__, mp_obj_new_str((byte*)vstr_str(&path), vstr_len(&path), false));
} else { // MP_IMPORT_STAT_FILE
do_load(module_obj, &path);
// TODO: We cannot just break here, at the very least, we must execute