summaryrefslogtreecommitdiff
path: root/astroid/inference.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-12-06 17:06:11 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2015-12-06 17:06:11 +0200
commit97c9092852d69f9b98b1276e3d10e9d29c7c0224 (patch)
tree7d52ab7622495bcf0961727d462ca6bb90e4c7e0 /astroid/inference.py
parentcf052851cab3176fc6442114cbdc8194b24b5b2e (diff)
downloadastroid-97c9092852d69f9b98b1276e3d10e9d29c7c0224.tar.gz
Add two new exceptions, AstroidImportError and AstroidSyntaxError.
They are subclasses of AstroidBuildingException and are raised when a module can't be imported from various reasons. Also do_import_module lets the errors to bubble up without converting them to InferenceError. This particular conversion happens only during the inference.
Diffstat (limited to 'astroid/inference.py')
-rw-r--r--astroid/inference.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/astroid/inference.py b/astroid/inference.py
index 45f31ff..7b2aa6b 100644
--- a/astroid/inference.py
+++ b/astroid/inference.py
@@ -130,10 +130,16 @@ def infer_import(self, context=None, asname=True):
name = context.lookupname
if name is None:
raise exceptions.InferenceError(node=self, context=context)
- if asname:
- yield self.do_import_module(self.real_name(name))
- else:
- yield self.do_import_module(name)
+
+ try:
+ if asname:
+ yield self.do_import_module(self.real_name(name))
+ else:
+ yield self.do_import_module(name)
+ except exceptions.AstroidBuildingException as exc:
+ util.reraise(exceptions.InferenceError(node=self, error=exc,
+ context=context))
+
nodes.Import._infer = infer_import
@@ -152,7 +158,13 @@ def infer_import_from(self, context=None, asname=True):
raise exceptions.InferenceError(node=self, context=context)
if asname:
name = self.real_name(name)
- module = self.do_import_module()
+
+ try:
+ module = self.do_import_module()
+ except exceptions.AstroidBuildingException as exc:
+ util.reraise(exceptions.InferenceError(node=self, error=exc,
+ context=context))
+
try:
context = contextmod.copy_context(context)
context.lookupname = name
@@ -277,7 +289,7 @@ def infer_subscript(self, context=None):
except (IndexError, TypeError, AttributeError) as exc:
util.reraise(exceptions.InferenceError(node=self, error=exc,
context=context))
-
+
# Prevent inferring if the inferred subscript
# is the same as the original subscripted object.
if self is assigned or assigned is util.Uninferable: