diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 4f4d951213f1..ee10b37bd509 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -192,9 +192,13 @@ public class PyBlock implements ASTBlock { childIndent = Indent.getNormalIndent(); } } - else if ((parentType == PyElementTypes.PARENTHESIZED_EXPRESSION || parentType == PyElementTypes.GENERATOR_EXPRESSION) && - hasLineBreaksBefore(child, 1)) { - childIndent = Indent.getNormalIndent(); + else if ((parentType == PyElementTypes.PARENTHESIZED_EXPRESSION || parentType == PyElementTypes.GENERATOR_EXPRESSION)) { + if (childType == PyTokenTypes.RPAR || !hasLineBreaksBefore(child, 1)) { + childIndent = Indent.getNoneIndent(); + } + else { + childIndent = Indent.getNormalIndent(); + } } if (isAfterStatementList(child) && !hasLineBreaksBefore(child, 2)) { // maybe enter was pressed and cut us from a previous (nested) statement list diff --git a/python/testData/formatter/tupleClosingParen.py b/python/testData/formatter/tupleClosingParen.py new file mode 100644 index 000000000000..7a97972be2d6 --- /dev/null +++ b/python/testData/formatter/tupleClosingParen.py @@ -0,0 +1,4 @@ +tuple = ( + 'value', + 'value', + ) \ No newline at end of file diff --git a/python/testData/formatter/tupleClosingParen_after.py b/python/testData/formatter/tupleClosingParen_after.py new file mode 100644 index 000000000000..cfd86394a88d --- /dev/null +++ b/python/testData/formatter/tupleClosingParen_after.py @@ -0,0 +1,4 @@ +tuple = ( + 'value', + 'value', +) \ No newline at end of file diff --git a/python/testData/intentions/afterConvertTripleQuotedString.py b/python/testData/intentions/afterConvertTripleQuotedString.py index 2736bd1ffbf0..d3cc2560d372 100644 --- a/python/testData/intentions/afterConvertTripleQuotedString.py +++ b/python/testData/intentions/afterConvertTripleQuotedString.py @@ -4,4 +4,4 @@ if True: '\n' ' Let\'s go.\n' ' And they went out.' - ) \ No newline at end of file + ) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index f21f5bdf8200..180aa90a5fca 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -199,7 +199,10 @@ public class PyFormatterTest extends PyTestCase { public void testSpaceWithinBraces() { // PY-8069 settings().getCustomSettings(PyCodeStyleSettings.class).SPACE_WITHIN_BRACES = true; doTest(); + } + public void testTupleClosingParen() { // PY-7946 + doTest(); } public void testPsiFormatting() { // IDEA-69724