diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 46908b2857d1..2e6744297aaa 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -183,7 +183,8 @@ public class PyBlock implements ASTBlock { childIndent = Indent.getNormalIndent(); } } - else if (parentType == PyElementTypes.PARENTHESIZED_EXPRESSION && hasLineBreaksBefore(child, 1)) { + else if ((parentType == PyElementTypes.PARENTHESIZED_EXPRESSION || parentType == PyElementTypes.GENERATOR_EXPRESSION) && + hasLineBreaksBefore(child, 1)) { childIndent = Indent.getNormalIndent(); } diff --git a/python/testData/formatter/indentInGenerator.py b/python/testData/formatter/indentInGenerator.py new file mode 100644 index 000000000000..1bf850828538 --- /dev/null +++ b/python/testData/formatter/indentInGenerator.py @@ -0,0 +1,3 @@ +def dbl(): + return ( + (a, a) for a in []) diff --git a/python/testData/formatter/indentInGenerator_after.py b/python/testData/formatter/indentInGenerator_after.py new file mode 100644 index 000000000000..1bf850828538 --- /dev/null +++ b/python/testData/formatter/indentInGenerator_after.py @@ -0,0 +1,3 @@ +def dbl(): + return ( + (a, a) for a in []) diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index 02b2ec9186ad..d450579fb31f 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -144,6 +144,10 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + public void testIndentInGenerator() { // PY-6219 + doTest(); + } + public void testPsiFormatting() { // IDEA-69724 String initial = "def method_name(\n" +