Fix some issues with import path errors.

This commit is contained in:
Dave Halter
2015-04-21 18:45:12 +02:00
parent 13267adfc2
commit 05554a1c89
2 changed files with 13 additions and 4 deletions

View File

@@ -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)

View File

@@ -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