diff --git a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java index 69469754d770..515c00ccbbfd 100644 --- a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java +++ b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java @@ -99,6 +99,8 @@ public class PythonFormattingModelBuilder implements FormattingModelBuilderEx, C .afterInside(RARROW, ANNOTATION).spaces(1) .between(allButLambda(), PARAMETER_LIST).spaceIf(commonSettings.SPACE_BEFORE_METHOD_PARENTHESES) + .afterInside(LBRACE, DICT_LITERAL_EXPRESSION).spaceIf(pySettings.SPACE_WITHIN_BRACES, pySettings.DICT_NEW_LINE_AFTER_LEFT_BRACE) + .beforeInside(RBRACE, DICT_LITERAL_EXPRESSION).spaceIf(pySettings.SPACE_WITHIN_BRACES, pySettings.DICT_NEW_LINE_BEFORE_RIGHT_BRACE) .before(COLON).spaceIf(pySettings.SPACE_BEFORE_PY_COLON) .after(COMMA).spaceIf(commonSettings.SPACE_AFTER_COMMA) @@ -115,8 +117,6 @@ public class PythonFormattingModelBuilder implements FormattingModelBuilderEx, C .withinPairInside(LPAR, RPAR, PARENTHESIZED_EXPRESSION).spaces(0) .before(LBRACKET).spaceIf(pySettings.SPACE_BEFORE_LBRACKET) - .afterInside(LBRACE, DICT_LITERAL_EXPRESSION).spaceIf(pySettings.SPACE_WITHIN_BRACES, pySettings.DICT_NEW_LINE_AFTER_LEFT_BRACE) - .beforeInside(RBRACE, DICT_LITERAL_EXPRESSION).spaceIf(pySettings.SPACE_WITHIN_BRACES, pySettings.DICT_NEW_LINE_BEFORE_RIGHT_BRACE) .withinPair(LBRACE, RBRACE).spaceIf(pySettings.SPACE_WITHIN_BRACES) .withinPair(LBRACKET, RBRACKET).spaceIf(commonSettings.SPACE_WITHIN_BRACKETS) diff --git a/python/testData/formatter/forceNewLineBeforeRightBraceInDictAfterColon.py b/python/testData/formatter/forceNewLineBeforeRightBraceInDictAfterColon.py new file mode 100644 index 000000000000..f50b6b44d780 --- /dev/null +++ b/python/testData/formatter/forceNewLineBeforeRightBraceInDictAfterColon.py @@ -0,0 +1,11 @@ +incoming_invite_post_schema = { + "definitions": { + "player": { + "type": "object", + "properties": { + "id": { + "type": "integer" + } + },} + } +} diff --git a/python/testData/formatter/forceNewLineBeforeRightBraceInDictAfterColon_after.py b/python/testData/formatter/forceNewLineBeforeRightBraceInDictAfterColon_after.py new file mode 100644 index 000000000000..5efe39606c35 --- /dev/null +++ b/python/testData/formatter/forceNewLineBeforeRightBraceInDictAfterColon_after.py @@ -0,0 +1,12 @@ +incoming_invite_post_schema = { + "definitions": { + "player": { + "type": "object", + "properties": { + "id": { + "type": "integer" + } + }, + } + } +} diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index 9520cf90f0a3..575abfd664be 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -612,6 +612,12 @@ public class PyFormatterTest extends PyTestCase { getPythonCodeStyleSettings().DICT_NEW_LINE_BEFORE_RIGHT_BRACE = true; doTest(); } + + // PY-17674 + public void testForceNewLineBeforeRightBraceInDictAfterColon() { + getPythonCodeStyleSettings().DICT_NEW_LINE_BEFORE_RIGHT_BRACE = true; + doTest(); + } // PY-16393 public void testHangingIndentDetectionIgnoresComments() {