diff options
Diffstat (limited to 'astroid/protocols.py')
-rw-r--r-- | astroid/protocols.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/astroid/protocols.py b/astroid/protocols.py index 30303dec..bd1d594f 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -443,7 +443,10 @@ def _infer_context_manager(self, mgr, context): # Get the first yield point. If it has multiple yields, # then a RuntimeError will be raised. # TODO(cpopa): Handle flows. - yield_point = next(func.nodes_of_class(nodes.Yield), None) + possible_yield_points = func.nodes_of_class(nodes.Yield) + # Ignore yields in nested functions + yield_point = next((node for node in possible_yield_points + if node.scope() == func), None) if yield_point: if not yield_point.value: # TODO(cpopa): an empty yield. Should be wrapped to Const. |