forked from VimPlug/jedi
improved import positioning errors in static analysis
This commit is contained in:
@@ -594,7 +594,7 @@ class Script(object):
|
||||
iw = imports.ImportWrapper(self._evaluator, i,
|
||||
nested_resolve=True).follow()
|
||||
if i.is_nested() and any(not isinstance(i, pr.Module) for i in iw):
|
||||
analysis.add(self._evaluator, 'import-error', i)
|
||||
analysis.add(self._evaluator, 'import-error', i.namespace.names[-1])
|
||||
for stmt in sorted(stmts, key=lambda obj: obj.start_pos):
|
||||
if not (isinstance(stmt.parent, pr.ForFlow)
|
||||
and stmt.parent.set_stmt == stmt):
|
||||
|
||||
@@ -32,7 +32,9 @@ from jedi.evaluate.cache import memoize_default, NO_DEFAULT
|
||||
|
||||
|
||||
class ModuleNotFound(Exception):
|
||||
pass
|
||||
def __init__(self, name_part):
|
||||
super(ModuleNotFound, self).__init__()
|
||||
self.name_part = name_part
|
||||
|
||||
|
||||
class ImportWrapper(pr.Base):
|
||||
@@ -166,8 +168,8 @@ class ImportWrapper(pr.Base):
|
||||
if self.import_path:
|
||||
try:
|
||||
scope, rest = self._importer.follow_file_system()
|
||||
except ModuleNotFound:
|
||||
analysis.add(self._evaluator, 'import-error', self.import_stmt)
|
||||
except ModuleNotFound as e:
|
||||
analysis.add(self._evaluator, 'import-error', e.name_part)
|
||||
return []
|
||||
|
||||
if self.import_stmt.is_nested() and not self.nested_resolve:
|
||||
@@ -202,7 +204,8 @@ class ImportWrapper(pr.Base):
|
||||
scopes = [ImportWrapper.GlobalNamespace]
|
||||
debug.dbg('after import: %s', scopes)
|
||||
if not scopes:
|
||||
analysis.add(self._evaluator, 'import-error', self.import_stmt)
|
||||
analysis.add(self._evaluator, 'import-error',
|
||||
self._importer.import_path[-1])
|
||||
self._evaluator.recursion_detector.pop_stmt()
|
||||
return scopes
|
||||
|
||||
@@ -442,7 +445,7 @@ class _Importer(object):
|
||||
rest = self.str_import_path()[i:]
|
||||
break
|
||||
else:
|
||||
raise ModuleNotFound('The module you searched has not been found')
|
||||
raise ModuleNotFound(s)
|
||||
|
||||
path = current_namespace[1]
|
||||
is_package_directory = current_namespace[2]
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|
||||
#! import-error
|
||||
#! 7 import-error
|
||||
import not_existing
|
||||
|
||||
import os
|
||||
|
||||
from os.path import abspath
|
||||
#! import-error
|
||||
#! 20 import-error
|
||||
from os.path import not_existing
|
||||
|
||||
from datetime import date
|
||||
@@ -14,10 +14,12 @@ date.today
|
||||
#! 5 attribute-error
|
||||
date.not_existing_attribute
|
||||
|
||||
#! import-error
|
||||
#! 26 import-error
|
||||
from datetime.date import today
|
||||
|
||||
#! import-error
|
||||
#! 16 import-error
|
||||
import datetime.date
|
||||
#! 7 import-error
|
||||
import not_existing_nested.date
|
||||
|
||||
import os.path
|
||||
|
||||
@@ -16,7 +16,7 @@ try:
|
||||
except ImportError:
|
||||
pass
|
||||
try:
|
||||
#! import-error
|
||||
#! 7 import-error
|
||||
import not_existing_import
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user