diff --git a/python/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java b/python/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java index 69e6e3379b91..c56d1dc716f7 100644 --- a/python/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java +++ b/python/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java @@ -147,8 +147,12 @@ public class PyResolveUtil { if ((roof != null) && (seeker != null) && !PsiTreeUtil.isAncestor(roof, seeker, false)) return null; // maybe we're capped by a class? param lists are not capped though syntactically inside the function. if (is_outside_param_list && refersFromMethodToClass(capFunction, seeker)) continue; - // names defined in a comprehension element are only visible inside it - if (seeker instanceof PyComprehensionElement && !PsiTreeUtil.isAncestor(seeker, elt, false)) continue; + // names defined in a comprehension element are only visible inside it or the list comp expressions directly above it + if (seeker instanceof PyComprehensionElement && + !(seeker.getParent() instanceof PyComprehensionElement) && + !PsiTreeUtil.isAncestor(seeker, elt, false)) { + continue; + } // check what we got if (seeker != null) { if (!processor.execute(seeker, ResolveState.initial())) { diff --git a/python/testData/resolve/NestedListComp.py b/python/testData/resolve/NestedListComp.py new file mode 100644 index 000000000000..c339579c356a --- /dev/null +++ b/python/testData/resolve/NestedListComp.py @@ -0,0 +1,3 @@ +lst1 = [[1,2,3],[4,5,6],[7,8,9]] +lst2 = [xx for yy in lst1 for xx in yy] +# diff --git a/python/testSrc/com/jetbrains/python/PyResolveTest.java b/python/testSrc/com/jetbrains/python/PyResolveTest.java index eb1d4806372a..9a780ab5517c 100644 --- a/python/testSrc/com/jetbrains/python/PyResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyResolveTest.java @@ -405,4 +405,8 @@ public class PyResolveTest extends PyResolveTestCase { public void testResolveInGenerator() { assertResolvesTo(PyTargetExpression.class, "foo"); } + + public void testNestedListComp() { // PY-3068 + assertResolvesTo(PyTargetExpression.class, "yy"); + } } \ No newline at end of file