diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 46810209418a..6f554254bf7b 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -295,7 +295,8 @@ public class PyBlock implements ASTBlock { } if (childType == PyTokenTypes.RPAR) { childIndent = Indent.getNoneIndent(); - if (!hasHangingIndent(myNode.getPsi())) { + // Don't have hanging indent and is not going to have it due to the setting about opening parenthesis + if (!hasHangingIndent(myNode.getPsi()) && !settings.FROM_IMPORT_NEW_LINE_AFTER_LEFT_PARENTHESIS) { childAlignment = getAlignmentForChildren(); } else if (settings.HANG_CLOSING_BRACKETS) { diff --git a/python/testData/formatter/fromImportParenthesesPlacementHangClosingParenthesis.py b/python/testData/formatter/fromImportParenthesesPlacementHangClosingParenthesis.py new file mode 100644 index 000000000000..fb69478bd4e4 --- /dev/null +++ b/python/testData/formatter/fromImportParenthesesPlacementHangClosingParenthesis.py @@ -0,0 +1,11 @@ +from module import (foo, bar) +from module import (foo, bar,) +from module import (foo, bar, baz, quux) +from module import (foo, + bar) +from module import (foo, + bar, + ) +from module import ( + foo, + bar) \ No newline at end of file diff --git a/python/testData/formatter/fromImportParenthesesPlacementHangClosingParenthesis_after.py b/python/testData/formatter/fromImportParenthesesPlacementHangClosingParenthesis_after.py new file mode 100644 index 000000000000..a91d6d73655d --- /dev/null +++ b/python/testData/formatter/fromImportParenthesesPlacementHangClosingParenthesis_after.py @@ -0,0 +1,17 @@ +from module import (foo, bar) +from module import (foo, bar, ) +from module import ( + foo, bar, baz, quux + ) +from module import ( + foo, + bar + ) +from module import ( + foo, + bar, + ) +from module import ( + foo, + bar + ) diff --git a/python/testData/formatter/fromImportParenthesesPlacement_after.py b/python/testData/formatter/fromImportParenthesesPlacement_after.py index fbf0e7a00dc0..ae41cfed13cc 100644 --- a/python/testData/formatter/fromImportParenthesesPlacement_after.py +++ b/python/testData/formatter/fromImportParenthesesPlacement_after.py @@ -2,15 +2,15 @@ from module import (foo, bar) from module import (foo, bar, ) from module import ( foo, bar, baz, quux - ) +) from module import ( foo, bar - ) +) from module import ( foo, bar, - ) +) from module import ( foo, bar diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index 8843ae87bb97..02544de4aca9 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -741,7 +741,6 @@ public class PyFormatterTest extends PyTestCase { } // PY-20633 - // XXX causes jumping closing parenthesis, because of the hanging indent detection public void testFromImportParenthesesPlacement() { getPythonCodeStyleSettings().FROM_IMPORT_NEW_LINE_AFTER_LEFT_PARENTHESIS = true; getPythonCodeStyleSettings().FROM_IMPORT_NEW_LINE_BEFORE_RIGHT_PARENTHESIS = true; @@ -749,6 +748,16 @@ public class PyFormatterTest extends PyTestCase { getCodeStyleSettings().setRightMargin(PythonLanguage.INSTANCE, 35); doTest(); } + + // PY-20633 + public void testFromImportParenthesesPlacementHangClosingParenthesis() { + getPythonCodeStyleSettings().FROM_IMPORT_NEW_LINE_AFTER_LEFT_PARENTHESIS = true; + getPythonCodeStyleSettings().FROM_IMPORT_NEW_LINE_BEFORE_RIGHT_PARENTHESIS = true; + getPythonCodeStyleSettings().HANG_CLOSING_BRACKETS = true; + getCommonCodeStyleSettings().SPACE_AFTER_COLON = true; + getCodeStyleSettings().setRightMargin(PythonLanguage.INSTANCE, 35); + doTest(); + } public void testVariableAnnotations() { runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest);