diff --git a/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java b/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java index bc3d6d795cb8..c58265df1fff 100644 --- a/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java +++ b/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java @@ -32,7 +32,6 @@ import com.jetbrains.python.psi.impl.PyAugAssignmentStatementNavigator; import com.jetbrains.python.psi.impl.PyEvaluator; import com.jetbrains.python.psi.impl.PyImportStatementNavigator; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -476,7 +475,7 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor { } final Instruction head = myBuilder.prevInstruction; final PyElsePart elsePart = node.getElsePart(); - if (elsePart == null && !nonEmptyIterationSource(source)) { + if (elsePart == null && !PyEvaluator.evaluateAsBoolean(source, false)) { myBuilder.addPendingEdge(node, myBuilder.prevInstruction); } final PyStatementList list = forPart.getStatementList(); @@ -511,13 +510,6 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor { myBuilder.flowAbrupted(); } - private static boolean nonEmptyIterationSource(@Nullable PyExpression source) { - return - source instanceof PySequenceExpression && !((PySequenceExpression)source).isEmpty() || - source instanceof PyStringLiteralExpression && !((PyStringLiteralExpression)source).getStringValue().isEmpty() || - source instanceof PyParenthesizedExpression && nonEmptyIterationSource(((PyParenthesizedExpression)source).getContainedExpression()); - } - @Override public void visitPyBreakStatement(final PyBreakStatement node) { myBuilder.startNode(node); diff --git a/python/testData/codeInsight/controlflow/fortrycontinue.txt b/python/testData/codeInsight/controlflow/fortrycontinue.txt index bc5ad352e7f1..edf39b7f813c 100644 --- a/python/testData/codeInsight/controlflow/fortrycontinue.txt +++ b/python/testData/codeInsight/controlflow/fortrycontinue.txt @@ -2,7 +2,7 @@ 1(2) element: PyAssignmentStatement 2(3) WRITE ACCESS: tests 3(4) element: PyForStatement -4(5,17) READ ACCESS: tests +4(5) READ ACCESS: tests 5(6) element: PyTargetExpression: t 6(7) WRITE ACCESS: t 7(8) element: PyTryExceptStatement