summaryrefslogtreecommitdiff
path: root/astroid/protocols.py
diff options
context:
space:
mode:
authorBryce Guinta <bryce.paul.guinta@gmail.com>2018-03-04 22:35:20 -0700
committerBryce Guinta <bryce.paul.guinta@gmail.com>2018-03-05 21:52:27 -0700
commit518e4a9dbff1ca041fa46a19c891a1d8a143f985 (patch)
treec4709ecff71d1a5e1b10e305211b240af606f23b /astroid/protocols.py
parentb7b0f338618aa206bf210d3e5a4f554594d0c44a (diff)
downloadastroid-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.py5
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.