diff options
author | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-03-04 22:35:20 -0700 |
---|---|---|
committer | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-03-05 21:52:27 -0700 |
commit | 518e4a9dbff1ca041fa46a19c891a1d8a143f985 (patch) | |
tree | c4709ecff71d1a5e1b10e305211b240af606f23b /astroid/protocols.py | |
parent | b7b0f338618aa206bf210d3e5a4f554594d0c44a (diff) | |
download | astroid-git-518e4a9dbff1ca041fa46a19c891a1d8a143f985.tar.gz |
Fix contextmanager transform for nested contextmanagers
Close PyCQA/pylint#1746
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. |