From 33c31e6384b46f377de51cf8c1e8ecfd1b1ffaca Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Sat, 18 Jan 2014 02:29:07 +0100 Subject: [PATCH] Make right par indent=none in import statement (PY-9075). --- .../com/jetbrains/python/formatter/PyBlock.java | 16 ++++++++++------ .../testData/formatter/indentParensInImport.py | 3 +++ .../formatter/indentParensInImport_after.py | 3 +++ .../com/jetbrains/python/PyFormatterTest.java | 4 ++++ 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 python/testData/formatter/indentParensInImport.py create mode 100644 python/testData/formatter/indentParensInImport_after.py diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 1085b7a18f5c..8afd35e009f2 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -213,13 +213,17 @@ public class PyBlock implements ASTBlock { } } else if (parentType == PyElementTypes.FROM_IMPORT_STATEMENT) { - if ((childType == PyElementTypes.IMPORT_ELEMENT || childType == PyTokenTypes.RPAR) && - _node.findChildByType(PyTokenTypes.LPAR) != null) { - if (myContext.getPySettings().ALIGN_MULTILINE_IMPORTS) { - childAlignment = getAlignmentForChildren(); + if (_node.findChildByType(PyTokenTypes.LPAR) != null) { + if (childType == PyElementTypes.IMPORT_ELEMENT) { + if (myContext.getPySettings().ALIGN_MULTILINE_IMPORTS) { + childAlignment = getAlignmentForChildren(); + } + else { + childIndent = Indent.getNormalIndent(); + } } - else { - childIndent = Indent.getNormalIndent(); + if (childType == PyTokenTypes.RPAR) { + childIndent = Indent.getNoneIndent(); } } } diff --git a/python/testData/formatter/indentParensInImport.py b/python/testData/formatter/indentParensInImport.py new file mode 100644 index 000000000000..ab20f1b5571b --- /dev/null +++ b/python/testData/formatter/indentParensInImport.py @@ -0,0 +1,3 @@ +from some.module import ( + thing + ) \ No newline at end of file diff --git a/python/testData/formatter/indentParensInImport_after.py b/python/testData/formatter/indentParensInImport_after.py new file mode 100644 index 000000000000..2ad9216af71c --- /dev/null +++ b/python/testData/formatter/indentParensInImport_after.py @@ -0,0 +1,3 @@ +from some.module import ( + thing +) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index f7290d328ee1..b745701d290d 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -366,6 +366,10 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + public void testIndentParensInImport() { // PY-9075 + doTest(); + } + private void doTest() { doTest(false); }