diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 2ca7cfb4ce47..d86e35c683e8 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -385,6 +385,9 @@ public class PyBlock implements ASTBlock { while (lastChild != null) { IElementType last_type = lastChild.getElementType(); if ( last_type == PyElementTypes.STATEMENT_LIST && hasLineBreakBefore(lastChild)) { + if (dedentAfterLastStatement((PyStatementList)lastChild.getPsi())) { + break; + } statementListsBelow++; } else if (statementListsBelow > 0 && lastChild.getPsi() instanceof PsiErrorElement) { diff --git a/python/testSrc/com/jetbrains/python/PyIndentTest.java b/python/testSrc/com/jetbrains/python/PyIndentTest.java index bece34187c21..1a145d66cfa9 100644 --- a/python/testSrc/com/jetbrains/python/PyIndentTest.java +++ b/python/testSrc/com/jetbrains/python/PyIndentTest.java @@ -167,6 +167,19 @@ public class PyIndentTest extends PyLightFixtureTestCase { " "); } + public void testUnindentAfterReturnNotLast() { // PY-289 + doTest("def foo():\n" + + " if True:\n" + + " return\n" + + "def bar(): pass", + "def foo():\n" + + " if True:\n" + + " return\n" + + " \n" + + "def bar(): pass" + ); + } + /* TODO: formatter core problem? public void testAlignListBeforeEquals() throws Exception {