From 02699bad102678273dcd6bbeb7d3f6100f4547fb Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Fri, 18 Jan 2019 18:54:30 +0100 Subject: Remove StopIteration handling which should not leak at all from inference --- astroid/inference.py | 10 +--------- astroid/protocols.py | 13 +++---------- 2 files changed, 4 insertions(+), 19 deletions(-) (limited to 'astroid') 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 -- cgit v1.2.1