PY-82712 False positive unreachable code after try / finally block if try has an if

GitOrigin-RevId: 53c13421523d780995fa83cc0625f6e99d5fe51f
This commit is contained in:
Aleksandr.Govenko
2025-07-17 17:19:57 +00:00
committed by intellij-monorepo-bot
parent a87109d664
commit cb34fe5953
3 changed files with 17 additions and 2 deletions
@@ -500,7 +500,7 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
}
exitInstructions.add(myBuilder.prevInstruction);
myBuilder.prevInstruction = addTransparentInstruction();
myBuilder.prevInstruction = addTransparentInstruction(node);
for (Instruction exitInstruction : Lists.reverse(exitInstructions)) {
myBuilder.addEdge(exitInstruction, myBuilder.prevInstruction);
@@ -4,7 +4,7 @@
3(16) exit context manager: context_manager
4(5,3) element: PyIfStatement
5(6,7,3) READ ACCESS: c
6(13) element: null. Condition: c:false
6(13,3) element: null. Condition: c:false
7(8) element: null. Condition: c:true
8(3,9) ASSERTTYPE ACCESS: c
9(10) element: PyStatementList
@@ -24,6 +24,21 @@ public class PyUnreachableCodeInspectionTest extends PyInspectionTestCase {
public void testUnreachable() {
runWithLanguageLevel(LanguageLevel.PYTHON26, () -> doTest());
}
// PY-82712
public void testIfInsideTryExcept() {
doTestByText("""
try:
if a==1:
print(0)
else:
print(1)
finally:
print(2)
print("Reachable")
""");
}
// PY-81482
public void testTryAssertFinally() {