From e95f4c7aa55d3d3a88a91886c2e7089cf2e843b3 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 5 Apr 2019 13:39:27 +0200 Subject: [PATCH] Fix module loading in Python 2 --- jedi/_compatibility.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index fbe4bba1..5f3f5b9f 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -149,6 +149,20 @@ def find_module_pre_py3(string, path=None, full_name=None, is_global_search=True module_file, module_path, description = imp.find_module(string, path) module_type = description[2] is_package = module_type is imp.PKG_DIRECTORY + if is_package: + # In Python 2 directory package imports are returned as folder + # paths, not __init__.py paths. + p = os.path.join(module_path, '__init__.py') + try: + module_file = open(p) + module_path = p + except FileNotFoundError: + pass + elif module_type != imp.PY_SOURCE: + if module_file is not None: + module_file.close() + module_file = None + if module_file is None: code = None return None, is_package