mirror of
https://github.com/davidhalter/jedi.git
synced 2026-08-13 07:51:00 +08:00
Add a better comment for imports
This commit is contained in:
@@ -221,8 +221,15 @@ class Importer(object):
|
|||||||
base = module_context.py__package__().split('.')
|
base = module_context.py__package__().split('.')
|
||||||
if base == [''] or base == ['__main__']:
|
if base == [''] or base == ['__main__']:
|
||||||
base = []
|
base = []
|
||||||
# We need to care for two cases, the second is if it's a valid
|
# We need to care for two cases, the first one is if it's a valid
|
||||||
# Python
|
# Python import. This import has a properly defined module name
|
||||||
|
# chain like `foo.bar.baz` and an import in baz is made for
|
||||||
|
# `..lala.` It can then resolve to `foo.bar.lala`.
|
||||||
|
# The else here is a heuristic for all other cases, if for example
|
||||||
|
# in `foo` you search for `...bar`, it's obviously out of scope.
|
||||||
|
# However since Jedi tries to just do it's best, we help the user
|
||||||
|
# here, because he might have specified something wrong in his
|
||||||
|
# project.
|
||||||
if level <= len(base):
|
if level <= len(base):
|
||||||
# Here we basically rewrite the level to 0.
|
# Here we basically rewrite the level to 0.
|
||||||
base = tuple(base)
|
base = tuple(base)
|
||||||
|
|||||||
@@ -280,18 +280,14 @@ def test_get_modules_containing_name(evaluator, path, goal):
|
|||||||
@pytest.mark.parametrize('empty_sys_path', (False, True))
|
@pytest.mark.parametrize('empty_sys_path', (False, True))
|
||||||
def test_relative_imports_with_multiple_similar_directories(Script, path, empty_sys_path):
|
def test_relative_imports_with_multiple_similar_directories(Script, path, empty_sys_path):
|
||||||
dir = get_example_dir('issue1209')
|
dir = get_example_dir('issue1209')
|
||||||
|
script = Script(
|
||||||
|
"from .",
|
||||||
|
path=os.path.join(dir, path),
|
||||||
|
)
|
||||||
|
# TODO pass this project to the script as a param once that's possible.
|
||||||
if empty_sys_path:
|
if empty_sys_path:
|
||||||
script = Script(
|
|
||||||
"from .",
|
|
||||||
path=os.path.join(dir, path),
|
|
||||||
)
|
|
||||||
script._evaluator.project = Project(dir, smart_sys_path=False)
|
script._evaluator.project = Project(dir, smart_sys_path=False)
|
||||||
else:
|
else:
|
||||||
script = Script(
|
|
||||||
"from .",
|
|
||||||
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)
|
script._evaluator.project = Project(dir)
|
||||||
name, import_ = script.completions()
|
name, import_ = script.completions()
|
||||||
assert import_.name == 'import'
|
assert import_.name == 'import'
|
||||||
|
|||||||
Reference in New Issue
Block a user