From ffd9a6b4845080a77e33f6e55757a1ed216f67d1 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 28 Feb 2019 20:04:17 +0100 Subject: [PATCH] Make it possible to complete in non-Python files --- jedi/evaluate/sys_path.py | 6 +++--- test/test_evaluate/test_imports.py | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/jedi/evaluate/sys_path.py b/jedi/evaluate/sys_path.py index 1544acc2..01fe64af 100644 --- a/jedi/evaluate/sys_path.py +++ b/jedi/evaluate/sys_path.py @@ -210,9 +210,9 @@ def transform_path_to_dotted(sys_path, module_path): if module_path.endswith(suffix): module_path = module_path[:-len(suffix)] break - else: - # There should always be a suffix in a valid Python file on the path. - return None + # Once the suffix was removed we are using the files as we know them. This + # means that if someone uses an ending like .vim for a Python file, .vim + # will be part of the returned dotted part. for p in sys_path: if module_path.startswith(p): diff --git a/test/test_evaluate/test_imports.py b/test/test_evaluate/test_imports.py index dbf02c57..ff38efca 100644 --- a/test/test_evaluate/test_imports.py +++ b/test/test_evaluate/test_imports.py @@ -254,11 +254,13 @@ def test_compiled_import_none(monkeypatch, Script): assert not Script('import sys').goto_definitions() -def test_relative_imports_with_multiple_similar_directories(Script): +@pytest.mark.parametrize( + 'path', ('api/whatever/test_this.py', 'api/whatever/file')) +def test_relative_imports_with_multiple_similar_directories(Script, path): dir = get_example_dir('issue1209') script = Script( "from .", - path=os.path.join(dir, 'api/whatever/test_this.py') + path=os.path.join(dir, path) ) # TODO pass this project to the script as a param once that's possible. script._evaluator.project = Project(dir)