1
0
forked from VimPlug/jedi

improved import positioning errors in static analysis

This commit is contained in:
Dave Halter
2014-05-16 17:20:45 +02:00
parent 9bf50e6022
commit ca2cc65686
4 changed files with 16 additions and 11 deletions

View File

@@ -594,7 +594,7 @@ class Script(object):
iw = imports.ImportWrapper(self._evaluator, i, iw = imports.ImportWrapper(self._evaluator, i,
nested_resolve=True).follow() nested_resolve=True).follow()
if i.is_nested() and any(not isinstance(i, pr.Module) for i in iw): 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): for stmt in sorted(stmts, key=lambda obj: obj.start_pos):
if not (isinstance(stmt.parent, pr.ForFlow) if not (isinstance(stmt.parent, pr.ForFlow)
and stmt.parent.set_stmt == stmt): and stmt.parent.set_stmt == stmt):

View File

@@ -32,7 +32,9 @@ from jedi.evaluate.cache import memoize_default, NO_DEFAULT
class ModuleNotFound(Exception): class ModuleNotFound(Exception):
pass def __init__(self, name_part):
super(ModuleNotFound, self).__init__()
self.name_part = name_part
class ImportWrapper(pr.Base): class ImportWrapper(pr.Base):
@@ -166,8 +168,8 @@ class ImportWrapper(pr.Base):
if self.import_path: if self.import_path:
try: try:
scope, rest = self._importer.follow_file_system() scope, rest = self._importer.follow_file_system()
except ModuleNotFound: except ModuleNotFound as e:
analysis.add(self._evaluator, 'import-error', self.import_stmt) analysis.add(self._evaluator, 'import-error', e.name_part)
return [] return []
if self.import_stmt.is_nested() and not self.nested_resolve: if self.import_stmt.is_nested() and not self.nested_resolve:
@@ -202,7 +204,8 @@ class ImportWrapper(pr.Base):
scopes = [ImportWrapper.GlobalNamespace] scopes = [ImportWrapper.GlobalNamespace]
debug.dbg('after import: %s', scopes) debug.dbg('after import: %s', scopes)
if not 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() self._evaluator.recursion_detector.pop_stmt()
return scopes return scopes
@@ -442,7 +445,7 @@ class _Importer(object):
rest = self.str_import_path()[i:] rest = self.str_import_path()[i:]
break break
else: else:
raise ModuleNotFound('The module you searched has not been found') raise ModuleNotFound(s)
path = current_namespace[1] path = current_namespace[1]
is_package_directory = current_namespace[2] is_package_directory = current_namespace[2]

View File

@@ -1,11 +1,11 @@
#! import-error #! 7 import-error
import not_existing import not_existing
import os import os
from os.path import abspath from os.path import abspath
#! import-error #! 20 import-error
from os.path import not_existing from os.path import not_existing
from datetime import date from datetime import date
@@ -14,10 +14,12 @@ date.today
#! 5 attribute-error #! 5 attribute-error
date.not_existing_attribute date.not_existing_attribute
#! import-error #! 26 import-error
from datetime.date import today from datetime.date import today
#! import-error #! 16 import-error
import datetime.date import datetime.date
#! 7 import-error
import not_existing_nested.date
import os.path import os.path

View File

@@ -16,7 +16,7 @@ try:
except ImportError: except ImportError:
pass pass
try: try:
#! import-error #! 7 import-error
import not_existing_import import not_existing_import
except AttributeError: except AttributeError:
pass pass