mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-17 19:15:55 +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)
|
helpers.check_error_statements(module, self._pos)
|
||||||
completion_names = []
|
completion_names = []
|
||||||
if names is not None:
|
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)
|
i = imports.get_importer(self._evaluator, imp_names, module, level)
|
||||||
completion_names = i.completion_names(self._evaluator, only_modules)
|
completion_names = i.completion_names(self._evaluator, only_modules)
|
||||||
|
|
||||||
@@ -287,6 +287,7 @@ class Script(object):
|
|||||||
module = self._parser.module()
|
module = self._parser.module()
|
||||||
names, level, _, _ = helpers.check_error_statements(module, self._pos)
|
names, level, _, _ = helpers.check_error_statements(module, self._pos)
|
||||||
if names:
|
if names:
|
||||||
|
names = [str(n) for n in names]
|
||||||
i = imports.get_importer(self._evaluator, names, module, level)
|
i = imports.get_importer(self._evaluator, names, module, level)
|
||||||
return i.follow(self._evaluator)
|
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):
|
class _Importer(object):
|
||||||
def __init__(self, evaluator, import_path, module, level=0):
|
def __init__(self, evaluator, import_path, module, level=0):
|
||||||
"""
|
"""
|
||||||
@@ -241,7 +247,7 @@ class _Importer(object):
|
|||||||
if dir_name:
|
if dir_name:
|
||||||
import_path.insert(0, dir_name)
|
import_path.insert(0, dir_name)
|
||||||
else:
|
else:
|
||||||
analysis.add(self._evaluator, 'import-error', import_path[-1])
|
_add_error(self._evaluator, import_path[-1])
|
||||||
import_path = []
|
import_path = []
|
||||||
|
|
||||||
# TODO add import error.
|
# TODO add import error.
|
||||||
@@ -299,6 +305,8 @@ class _Importer(object):
|
|||||||
scope, rest = self.follow_file_system()
|
scope, rest = self.follow_file_system()
|
||||||
except ModuleNotFound:
|
except ModuleNotFound:
|
||||||
return []
|
return []
|
||||||
|
if scope is None:
|
||||||
|
return []
|
||||||
if rest:
|
if rest:
|
||||||
# follow the rest of the import (not FS -> classes, functions)
|
# follow the rest of the import (not FS -> classes, functions)
|
||||||
return self.follow_rest(scope, rest)
|
return self.follow_rest(scope, rest)
|
||||||
@@ -505,7 +513,7 @@ class _Importer(object):
|
|||||||
paths = base.py__path__()
|
paths = base.py__path__()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# The module is not a package.
|
# The module is not a package.
|
||||||
analysis.add(self._evaluator, 'import-error', import_path[-1])
|
_add_error(self._evaluator, import_path[-1])
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
debug.dbg('search_module %s in paths %s', module_name, paths)
|
debug.dbg('search_module %s in paths %s', module_name, paths)
|
||||||
@@ -524,7 +532,7 @@ class _Importer(object):
|
|||||||
sys.path = temp
|
sys.path = temp
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# The module is not a package.
|
# The module is not a package.
|
||||||
analysis.add(self._evaluator, 'import-error', import_path[-1])
|
_add_error(self._evaluator, import_path[-1])
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
source = None
|
source = None
|
||||||
|
|||||||
Reference in New Issue
Block a user