From 6838043503f9e05c05ecddaa866f06a890329a95 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Wed, 11 Jan 2017 19:43:39 +0300 Subject: [PATCH] PY-10182 Use same indentation level instead of alignment for closing parenthesis in "from" imports This way the position of the parenthesis doesn't depend on the option ALIGN_MULTIPLE_IMPORTS, because if it's disabled and there is hanging indent, import elements inside parentheses don't have any alignment to share. --- python/src/com/jetbrains/python/formatter/PyBlock.java | 5 ++++- python/testSrc/com/jetbrains/python/PyFormatterTest.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 4898bca87aca..d2a8b9d61b30 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -283,9 +283,12 @@ public class PyBlock implements ASTBlock { } if (childType == PyTokenTypes.RPAR) { childIndent = Indent.getNoneIndent(); - if (!hasHangingIndent(myNode.getPsi()) || settings.HANG_CLOSING_BRACKETS) { + if (!hasHangingIndent(myNode.getPsi())) { childAlignment = getAlignmentForChildren(); } + else if (settings.HANG_CLOSING_BRACKETS) { + childIndent = Indent.getNormalIndent(); + } } } } diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index f6a5359472d4..167e70faae9d 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -676,6 +676,8 @@ public class PyFormatterTest extends PyTestCase { // PY-10182 public void testHangClosingParenthesisInFromImport() { + // Shouldn't affect the result + getPythonCodeStyleSettings().ALIGN_MULTILINE_IMPORTS = false; getPythonCodeStyleSettings().HANG_CLOSING_BRACKETS = true; doTest(); } @@ -692,7 +694,7 @@ public class PyFormatterTest extends PyTestCase { doTest(); } - // PY-10182 + // PY-10182 public void testHangClosingParenthesisInListLiteral() { getPythonCodeStyleSettings().HANG_CLOSING_BRACKETS = true; doTest();