mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Some small import changes that fix a few of the broken test cases.
This commit is contained in:
@@ -115,7 +115,8 @@ class ImportWrapper(pr.Base):
|
|||||||
self._evaluator.find_types(s, from_import_name, is_goto)
|
self._evaluator.find_types(s, from_import_name, is_goto)
|
||||||
for s in types))
|
for s in types))
|
||||||
if not types:
|
if not types:
|
||||||
importer = get_importer(self._evaluator, tuple(import_path),
|
importer = get_importer(self._evaluator,
|
||||||
|
tuple(import_path + [from_import_name]),
|
||||||
module, self._import.level)
|
module, self._import.level)
|
||||||
module, _ = importer.follow_file_system()
|
module, _ = importer.follow_file_system()
|
||||||
if module is None:
|
if module is None:
|
||||||
@@ -129,6 +130,7 @@ class ImportWrapper(pr.Base):
|
|||||||
if is_goto and not rest:
|
if is_goto and not rest:
|
||||||
types = [s.name for s in types]
|
types = [s.name for s in types]
|
||||||
|
|
||||||
|
"""
|
||||||
# follow the rest of the import (not FS -> classes, functions)
|
# follow the rest of the import (not FS -> classes, functions)
|
||||||
if rest:
|
if rest:
|
||||||
if is_goto:
|
if is_goto:
|
||||||
@@ -141,6 +143,7 @@ class ImportWrapper(pr.Base):
|
|||||||
types = importer.follow_rest(types[0], rest)
|
types = importer.follow_rest(types[0], rest)
|
||||||
else:
|
else:
|
||||||
types = []
|
types = []
|
||||||
|
"""
|
||||||
debug.dbg('after import: %s', types)
|
debug.dbg('after import: %s', types)
|
||||||
#if not types:
|
#if not types:
|
||||||
# analysis.add(self._evaluator, 'import-error', importer.import_path[-1])
|
# analysis.add(self._evaluator, 'import-error', importer.import_path[-1])
|
||||||
@@ -188,19 +191,31 @@ def get_importer(evaluator, import_path, module, level=0):
|
|||||||
"""
|
"""
|
||||||
if level:
|
if level:
|
||||||
base = module.py__package__().split('.')
|
base = module.py__package__().split('.')
|
||||||
|
if base == ['']:
|
||||||
|
base = []
|
||||||
if level > len(base):
|
if level > len(base):
|
||||||
|
path = module.py__file__()
|
||||||
|
import_path = list(import_path)
|
||||||
|
for i in range(level):
|
||||||
|
path = os.path.dirname(path)
|
||||||
|
dir_name = os.path.basename(path)
|
||||||
|
if dir_name:
|
||||||
|
import_path.insert(0, dir_name)
|
||||||
|
else:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
# TODO add import error.
|
# TODO add import error.
|
||||||
debug.warning('Attempted relative import beyond top-level package.')
|
debug.warning('Attempted relative import beyond top-level package.')
|
||||||
# TODO this is just in the wrong place.
|
# This is not the proper way to do relative imports. However, since
|
||||||
raise NotImplementedError
|
# Jedi cannot be sure about the entry point, we just calculate an
|
||||||
return _Importer(evaluator, import_path, module, level)
|
# absolute path here.
|
||||||
|
return _Importer(evaluator, import_path, module, 0)
|
||||||
else:
|
else:
|
||||||
# Here we basically rewrite the level to 0.
|
# Here we basically rewrite the level to 0.
|
||||||
import_path = tuple(base) + import_path
|
import_path = tuple(base) + import_path
|
||||||
|
|
||||||
check_import_path = tuple(unicode(i) for i in import_path)
|
check_import_path = tuple(unicode(i) for i in import_path)
|
||||||
try:
|
try:
|
||||||
print(check_import_path)
|
|
||||||
return evaluator.import_cache[check_import_path]
|
return evaluator.import_cache[check_import_path]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
importer = _Importer(evaluator, import_path, module, level=0)
|
importer = _Importer(evaluator, import_path, module, level=0)
|
||||||
@@ -500,7 +515,9 @@ class _Importer(object):
|
|||||||
finally:
|
finally:
|
||||||
sys.path = temp
|
sys.path = temp
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise NotImplementedError
|
# The module is not a package.
|
||||||
|
analysis.add(self._evaluator, 'import-error', import_path[-1])
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
source = None
|
source = None
|
||||||
if is_pkg:
|
if is_pkg:
|
||||||
|
|||||||
@@ -2,6 +2,4 @@ a = ''
|
|||||||
|
|
||||||
from . import invisible_pkg
|
from . import invisible_pkg
|
||||||
|
|
||||||
the_pkg = invisible_pkg
|
|
||||||
|
|
||||||
invisible_pkg = 1
|
invisible_pkg = 1
|
||||||
|
|||||||
@@ -121,9 +121,6 @@ def test_import_priorities():
|
|||||||
from import_tree import the_pkg, invisible_pkg
|
from import_tree import the_pkg, invisible_pkg
|
||||||
#? int()
|
#? int()
|
||||||
invisible_pkg
|
invisible_pkg
|
||||||
# The renamed invisible_pkg in that module (look at ``__init__.py``!)
|
|
||||||
#? float()
|
|
||||||
the_pkg.foo
|
|
||||||
|
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user