mirror of
https://github.com/davidhalter/jedi.git
synced 2026-11-02 04:37:31 +08:00
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 parent
ad5170a37a
commit
4b276bae87
6 files changed
+56
-22
No files matched your search
@@ -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