summaryrefslogtreecommitdiff
path: root/astroid
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-01-18 18:54:30 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2019-01-18 18:54:30 +0100
commit02699bad102678273dcd6bbeb7d3f6100f4547fb (patch)
treeb973f9b8b9065f0835bd4bfb0f8addf14f7e9ab1 /astroid
parent0e1ab4ac02b1946851496585459930f0d7b6f03e (diff)
downloadastroid-git-02699bad102678273dcd6bbeb7d3f6100f4547fb.tar.gz
Remove StopIteration handling which should not leak at all from inference
Diffstat (limited to 'astroid')
-rw-r--r--astroid/inference.py10
-rw-r--r--astroid/protocols.py13
2 files changed, 4 insertions, 19 deletions
diff --git a/astroid/inference.py b/astroid/inference.py
index 09c6eb60..dbcf8a62 100644
--- a/astroid/inference.py
+++ b/astroid/inference.py
@@ -874,15 +874,7 @@ def instance_getitem(self, index, context=None):
"Could not find __getitem__ for {node!r}.", node=self, context=context
)
- try:
- return next(method.infer_call_result(self, new_context))
- except StopIteration as exc:
- raise exceptions.InferenceError(
- message="Inference for {node!r}[{index!s}] failed.",
- node=self,
- index=index,
- context=context,
- ) from exc
+ return next(method.infer_call_result(self, new_context))
bases.Instance.getitem = instance_getitem
diff --git a/astroid/protocols.py b/astroid/protocols.py
index 86889b43..f3032caf 100644
--- a/astroid/protocols.py
+++ b/astroid/protocols.py
@@ -455,7 +455,7 @@ nodes.ExceptHandler.assigned_stmts = excepthandler_assigned_stmts
def _infer_context_manager(self, mgr, context):
try:
inferred = next(mgr.infer(context=context))
- except (StopIteration, exceptions.InferenceError):
+ except exceptions.InferenceError:
return
if isinstance(inferred, bases.Generator):
# Check if it is decorated with contextlib.contextmanager.
@@ -463,10 +463,7 @@ def _infer_context_manager(self, mgr, context):
if not func.decorators:
return
for decorator_node in func.decorators.nodes:
- try:
- decorator = next(decorator_node.infer(context))
- except StopIteration:
- return
+ decorator = next(decorator_node.infer(context))
if isinstance(decorator, nodes.FunctionDef):
if decorator.qname() == _CONTEXTLIB_MGR:
break
@@ -493,11 +490,7 @@ def _infer_context_manager(self, mgr, context):
elif isinstance(inferred, bases.Instance):
try:
enter = next(inferred.igetattr("__enter__", context=context))
- except (
- StopIteration,
- exceptions.InferenceError,
- exceptions.AttributeInferenceError,
- ):
+ except (exceptions.InferenceError, exceptions.AttributeInferenceError):
return
if not isinstance(enter, bases.BoundMethod):
return