diff --git a/jedi/evaluate/sys_path.py b/jedi/evaluate/sys_path.py index 940ebf3d..4cbef176 100644 --- a/jedi/evaluate/sys_path.py +++ b/jedi/evaluate/sys_path.py @@ -232,7 +232,11 @@ def transform_path_to_dotted(sys_path, module_path): for p in sys_path: if module_path.startswith(p): # Strip the trailing slash/backslash - rest = module_path[len(p) + 1:] + rest = module_path[len(p):] + # On Windows a path can also use a slash. + if rest.startswith(os.path.sep) or rest.startswith('/'): + # Remove a slash in cases it's still there. + rest = rest[1:] if rest: split = rest.split(os.path.sep) diff --git a/test/test_evaluate/test_sys_path.py b/test/test_evaluate/test_sys_path.py index 2d014172..5885e112 100644 --- a/test/test_evaluate/test_sys_path.py +++ b/test/test_evaluate/test_sys_path.py @@ -94,6 +94,8 @@ _s = ['/a', '/b', '/c/d/'] (['/foo', '/foo/bar'], '/foo/bar/baz', ('baz',), False), (['/foo/bar', '/foo'], '/foo/bar/baz', ('baz',), False), + + (['/'], '/bar/baz.py', ('bar', 'baz',), False), ]) def test_transform_path_to_dotted(sys_path_, module_path, expected, is_package): # transform_path_to_dotted expects normalized absolute paths.