PY-20633 Don't need to call reformat twice to move right parenthesis in from imports sometimes

This commit is contained in:
Mikhail Golubev
2017-01-23 17:41:20 +03:00
parent 17c24b9daf
commit c5a51bf665
5 changed files with 43 additions and 5 deletions
@@ -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) {
@@ -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)
@@ -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
)
@@ -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
@@ -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);