diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 6f554254bf7b..e3427af2cc5b 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -617,7 +617,8 @@ public class PyBlock implements ASTBlock { myContext.getMode() == FormattingMode.ADJUST_INDENT) { return true; } - return !hasHangingIndent(myNode.getPsi()); + return !hasHangingIndent(myNode.getPsi()) && !(myNode.getElementType() == PyElementTypes.DICT_LITERAL_EXPRESSION && + myContext.getPySettings().DICT_NEW_LINE_AFTER_LEFT_BRACE); } if (myNode.getElementType() == PyElementTypes.ARGUMENT_LIST) { if (!myContext.getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS || hasHangingIndent(myNode.getPsi())) { diff --git a/python/testData/formatter/noAlignmentClosingBraceInDictLiteralWhenOpeningBraceIsForcedOnNewLine.py b/python/testData/formatter/noAlignmentClosingBraceInDictLiteralWhenOpeningBraceIsForcedOnNewLine.py new file mode 100644 index 000000000000..318891c69c57 --- /dev/null +++ b/python/testData/formatter/noAlignmentClosingBraceInDictLiteralWhenOpeningBraceIsForcedOnNewLine.py @@ -0,0 +1,3 @@ +d = {"foo": 1, + "bar": 2 + } \ No newline at end of file diff --git a/python/testData/formatter/noAlignmentClosingBraceInDictLiteralWhenOpeningBraceIsForcedOnNewLine_after.py b/python/testData/formatter/noAlignmentClosingBraceInDictLiteralWhenOpeningBraceIsForcedOnNewLine_after.py new file mode 100644 index 000000000000..7f322119f4a7 --- /dev/null +++ b/python/testData/formatter/noAlignmentClosingBraceInDictLiteralWhenOpeningBraceIsForcedOnNewLine_after.py @@ -0,0 +1,4 @@ +d = { + "foo": 1, + "bar": 2 +} diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index 02544de4aca9..831363ec3d21 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -484,6 +484,11 @@ public class PyFormatterTest extends PyTestCase { public void testAlignmentOfClosingBraceInDictLiteralWhenNoHangingIndent() { doTest(); } + + public void testNoAlignmentClosingBraceInDictLiteralWhenOpeningBraceIsForcedOnNewLine() { + getPythonCodeStyleSettings().DICT_NEW_LINE_AFTER_LEFT_BRACE = true; + doTest(); + } // PY-13004 public void testAlignmentOfClosingParenthesisOfArgumentListWhenNoHangingIndent() {