mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-16 02:27:06 +08:00
Fix some issues with import path errors.
This commit is contained in:
@@ -145,7 +145,7 @@ class Script(object):
|
||||
helpers.check_error_statements(module, self._pos)
|
||||
completion_names = []
|
||||
if names is not None:
|
||||
imp_names = tuple(n for n in names if n.end_pos < self._pos)
|
||||
imp_names = tuple(str(n) for n in names if n.end_pos < self._pos)
|
||||
i = imports.get_importer(self._evaluator, imp_names, module, level)
|
||||
completion_names = i.completion_names(self._evaluator, only_modules)
|
||||
|
||||
@@ -287,6 +287,7 @@ class Script(object):
|
||||
module = self._parser.module()
|
||||
names, level, _, _ = helpers.check_error_statements(module, self._pos)
|
||||
if names:
|
||||
names = [str(n) for n in names]
|
||||
i = imports.get_importer(self._evaluator, names, module, level)
|
||||
return i.follow(self._evaluator)
|
||||
|
||||
|
||||
@@ -203,6 +203,12 @@ def get_importer(evaluator, import_path, module, level=0):
|
||||
"""
|
||||
|
||||
|
||||
def _add_error(evaluator, name, message=None):
|
||||
if hasattr(name, 'parent'):
|
||||
# Should be a name, not a string!
|
||||
analysis.add(evaluator, 'import-error', name, message)
|
||||
|
||||
|
||||
class _Importer(object):
|
||||
def __init__(self, evaluator, import_path, module, level=0):
|
||||
"""
|
||||
@@ -241,7 +247,7 @@ class _Importer(object):
|
||||
if dir_name:
|
||||
import_path.insert(0, dir_name)
|
||||
else:
|
||||
analysis.add(self._evaluator, 'import-error', import_path[-1])
|
||||
_add_error(self._evaluator, import_path[-1])
|
||||
import_path = []
|
||||
|
||||
# TODO add import error.
|
||||
@@ -299,6 +305,8 @@ class _Importer(object):
|
||||
scope, rest = self.follow_file_system()
|
||||
except ModuleNotFound:
|
||||
return []
|
||||
if scope is None:
|
||||
return []
|
||||
if rest:
|
||||
# follow the rest of the import (not FS -> classes, functions)
|
||||
return self.follow_rest(scope, rest)
|
||||
@@ -505,7 +513,7 @@ class _Importer(object):
|
||||
paths = base.py__path__()
|
||||
except AttributeError:
|
||||
# The module is not a package.
|
||||
analysis.add(self._evaluator, 'import-error', import_path[-1])
|
||||
_add_error(self._evaluator, import_path[-1])
|
||||
return None
|
||||
else:
|
||||
debug.dbg('search_module %s in paths %s', module_name, paths)
|
||||
@@ -524,7 +532,7 @@ class _Importer(object):
|
||||
sys.path = temp
|
||||
except ImportError:
|
||||
# The module is not a package.
|
||||
analysis.add(self._evaluator, 'import-error', import_path[-1])
|
||||
_add_error(self._evaluator, import_path[-1])
|
||||
return None
|
||||
else:
|
||||
source = None
|
||||
|
||||
Reference in New Issue
Block a user