mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Errors in import module are now better reported
This commit is contained in:
@@ -146,11 +146,7 @@ class NestedImportModule(tree.Module):
|
|||||||
self._nested_import)
|
self._nested_import)
|
||||||
|
|
||||||
|
|
||||||
def _add_error(context, name, message=None):
|
def _add_error(context, name, message):
|
||||||
# Should be a name, not a string!
|
|
||||||
if message is None:
|
|
||||||
name_str = str(name.value) if isinstance(name, tree.Name) else name
|
|
||||||
message = 'No module named ' + name_str
|
|
||||||
if hasattr(name, 'parent') and context is not None:
|
if hasattr(name, 'parent') and context is not None:
|
||||||
analysis.add(context, 'import-error', name, message)
|
analysis.add(context, 'import-error', name, message)
|
||||||
else:
|
else:
|
||||||
@@ -311,14 +307,9 @@ class Importer(object):
|
|||||||
+ sys_path.check_sys_path_modifications(self.module_context)
|
+ sys_path.check_sys_path_modifications(self.module_context)
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.import_path:
|
|
||||||
try:
|
|
||||||
file_path = self.module_context.py__file__()
|
|
||||||
except AttributeError:
|
|
||||||
# Can be None for certain compiled modules like 'builtins'.
|
|
||||||
file_path = None
|
|
||||||
else:
|
|
||||||
if self._evaluator.environment.version_info.major == 2:
|
if self._evaluator.environment.version_info.major == 2:
|
||||||
|
file_path = self.module_context.py__file__()
|
||||||
|
if file_path is not None:
|
||||||
# Python2 uses an old strange way of importing relative imports.
|
# Python2 uses an old strange way of importing relative imports.
|
||||||
sys_path_mod.append(force_unicode(os.path.dirname(file_path)))
|
sys_path_mod.append(force_unicode(os.path.dirname(file_path)))
|
||||||
|
|
||||||
@@ -346,7 +337,8 @@ class Importer(object):
|
|||||||
for parent_module_context in context_set
|
for parent_module_context in context_set
|
||||||
])
|
])
|
||||||
except JediImportError:
|
except JediImportError:
|
||||||
_add_error(self.module_context, name)
|
message = 'No module named ' + '.'.join(import_names)
|
||||||
|
_add_error(self.module_context, name, message)
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
return context_set
|
return context_set
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user