diff options
Diffstat (limited to 'astroid/inference.py')
-rw-r--r-- | astroid/inference.py | 24 |
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: |