diff --git a/src/vm.cpp b/src/vm.cpp index eb296095..bedecd5b 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -217,9 +217,6 @@ namespace pkpy{ PyObject* VM::py_import(Str path, bool throw_err){ if(path.empty()) vm->ValueError("empty module name"); - - // std::cout << ">> py_import(" << path.escape() << ")" << std::endl; - auto f_join = [](const std::vector& cpnts){ std::stringstream ss; for(int i=0; i 128){ + ImportError("maximum recursion depth exceeded while importing"); + } + StrName name(path); // path to StrName PyObject* ext_mod = _modules.try_get(name); if(ext_mod != nullptr) return ext_mod; @@ -288,10 +286,9 @@ namespace pkpy{ auto _ = _import_context.scope(path, is_init); CodeObject_ code = compile(source, filename, EXEC_MODE); - auto all_cpnts = path.split(".", true); - Str name_cpnt = all_cpnts.back(); - all_cpnts.pop_back(); - PyObject* new_mod = new_module(name_cpnt, f_join(all_cpnts)); + Str name_cpnt = path_cpnts.back(); + path_cpnts.pop_back(); + PyObject* new_mod = new_module(name_cpnt, f_join(path_cpnts)); _exec(code, new_mod); new_mod->attr()._try_perfect_rehash(); return new_mod; diff --git a/tests/test2/a/__init__.py b/tests/test2/a/__init__.py index d0396b19..c2b30cc1 100644 --- a/tests/test2/a/__init__.py +++ b/tests/test2/a/__init__.py @@ -1 +1,3 @@ +ok = True + from ..b import D \ No newline at end of file diff --git a/tests/test2/utils/r.py b/tests/test2/utils/r.py index da470d87..33dbd4c5 100644 --- a/tests/test2/utils/r.py +++ b/tests/test2/utils/r.py @@ -1,8 +1,4 @@ value = '123' -# try: -# from test2.a import g -# exit(1) -# except ImportError: -# # circular import -# pass \ No newline at end of file +from test2.a import g +assert g.ok == True