diff --git a/jedi/modules.py b/jedi/modules.py index 5cc45e7f..b26c18ad 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -335,7 +335,9 @@ def sys_path_with_modifications(module): return sys_path if module.path is None: - return [] # support for modules without a path is intentionally bad. + # Support for modules without a path is bad, therefore return the + # normal path. + return list(get_sys_path()) curdir = os.path.abspath(os.curdir) with common.ignored(OSError): diff --git a/test/test_integration_import.py b/test/test_integration_import.py index 0c85a707..609b4cfd 100644 --- a/test/test_integration_import.py +++ b/test/test_integration_import.py @@ -28,6 +28,20 @@ def test_complete_on_empty_import(): assert Script("from datetime import ").completions() +def test_imports_on_global_namespace_without_path(): + """If the path is None, there shouldn't be any import problem""" + completions = Script("import operator").completions() + assert [c.name for c in completions] == ['operator'] + completions = Script("import operator", source_path= 'example.py').completions() + assert [c.name for c in completions] == ['operator'] + + # the first one has a path the second doesn't + completions = Script("import keyword", source_path='example.py').completions() + assert [c.name for c in completions] == ['keyword'] + completions = Script("import keyword").completions() + assert [c.name for c in completions] == ['keyword'] + + def test_named_import(): """named import - jedi-vim issue #8""" s = "import time as dt" diff --git a/test/test_utils.py b/test/test_utils.py index 78c931af..b6cd8586 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -49,6 +49,7 @@ class TestSetupReadline(): def test_import(self): s = 'from os.path import a' assert set(self.completions(s)) == set([s + 'ltsep', s + 'bspath']) + assert self.completions('import keyword') == ['import keyword'] def test_colorama(self): """