forked from VimPlug/jedi
The import resolution for namespace packages was wrong
With this change we can now include all parents of the script, which will make relative imports always work. Now the whole meta_path is scanned and not just importlib's PathFinder. Fixes #1183.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
from os.path import dirname, join
|
||||
|
||||
import pytest
|
||||
import py
|
||||
|
||||
from ..helpers import get_example_dir
|
||||
|
||||
|
||||
SYS_PATH = [join(dirname(__file__), d)
|
||||
@@ -72,3 +75,19 @@ def test_nested_namespace_package(Script):
|
||||
result = script.goto_definitions()
|
||||
|
||||
assert len(result) == 1
|
||||
|
||||
|
||||
def test_relative_import(Script, tmpdir):
|
||||
"""
|
||||
Attempt a relative import in a very simple namespace package.
|
||||
"""
|
||||
directory = get_example_dir('namespace_package_relative_import')
|
||||
# Need to copy the content in a directory where there's no __init__.py.
|
||||
py.path.local(directory).copy(tmpdir)
|
||||
file_path = join(tmpdir.strpath, "rel1.py")
|
||||
script = Script(path=file_path, line=1)
|
||||
d, = script.goto_definitions()
|
||||
assert d.name == 'int'
|
||||
d, = script.goto_assignments()
|
||||
assert d.name == 'name'
|
||||
assert d.module_name == 'rel2'
|
||||
|
||||
Reference in New Issue
Block a user