diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index 962d3dbf..bc48b86e 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -375,6 +375,11 @@ def load_module(path, name): # the QObject class. # See https://github.com/davidhalter/jedi/pull/483 return None + raise + except ImportError: + # If a module is "corrupt" or not really a Python module or whatever. + debug.warning('Module %s not importable.', path) + return None # Just access the cache after import, because of #59 as well as the very # complicated import structure of Python. module = sys.modules[dotted_path] diff --git a/test/test_evaluate/test_imports.py b/test/test_evaluate/test_imports.py index 5bc9075b..de913a4e 100644 --- a/test/test_evaluate/test_imports.py +++ b/test/test_evaluate/test_imports.py @@ -51,3 +51,9 @@ def test_flask_ext(script, name): assert name in [c.name for c in jedi.Script(script).completions()] finally: sys.path.remove(path) + + +@cwd_at('test/test_evaluate/') +def test_not_importable_file(): + src = 'import not_importable_file as x; x.' + assert not jedi.Script(src, path='example.py').completions()