From 6f01264ed3d591ffeb65e1526dea133edac68360 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 21 Mar 2017 17:20:10 +0100 Subject: [PATCH] Restructure import's module loading. --- jedi/evaluate/imports.py | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index 2e139df2..36d6f0a6 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -449,30 +449,29 @@ class Importer(object): def _load_module(evaluator, path=None, source=None, sys_path=None, parent_module=None): - def load(source): - dotted_path = path and compiled.dotted_from_fs_path(path, sys_path) - if path is not None and path.endswith(('.py', '.zip', '.egg')) \ - and dotted_path not in settings.auto_import_modules: - if source is None: - with open(path, 'rb') as f: - source = f.read() - else: - return compiled.load_module(evaluator, path) - p = path - p = FastParser(evaluator.grammar, source_to_unicode(source), p) - save_parser(path, p) - return p.get_root_node() - if sys_path is None: sys_path = evaluator.sys_path - cached = load_parser(path) - module_node = load(source) if cached is None else cached.get_root_node() - if isinstance(module_node, compiled.CompiledObject): - return module_node + dotted_path = path and compiled.dotted_from_fs_path(path, sys_path) + if path is not None and path.endswith(('.py', '.zip', '.egg')) \ + and dotted_path not in settings.auto_import_modules: - from jedi.evaluate.representation import ModuleContext - return ModuleContext(evaluator, module_node) + cached = load_parser(path) + if cached is None: + if source is None: + with open(path, 'rb') as f: + source = f.read() + + p = FastParser(evaluator.grammar, source_to_unicode(source), path) + save_parser(path, p) + module_node = p.get_root_node() + else: + module_node = cached.get_root_node() + + from jedi.evaluate.representation import ModuleContext + return ModuleContext(evaluator, module_node) + else: + return compiled.load_module(evaluator, path) def add_module(evaluator, module_name, module):