From e57ceea8f418d9217a4d33bbff907ad37171761b Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Dec 2012 16:29:53 +0100 Subject: [PATCH] don't delete space between . and 'import' (PY-8112) --- .../python/formatter/PythonFormattingModelBuilder.java | 1 + python/testData/formatter/spaceAfterRelativeImport.py | 1 + python/testData/formatter/spaceAfterRelativeImport_after.py | 1 + python/testSrc/com/jetbrains/python/PyFormatterTest.java | 4 ++++ 4 files changed, 7 insertions(+) create mode 100644 python/testData/formatter/spaceAfterRelativeImport.py create mode 100644 python/testData/formatter/spaceAfterRelativeImport_after.py diff --git a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java index 28b16126f316..46317138c123 100644 --- a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java +++ b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java @@ -80,6 +80,7 @@ public class PythonFormattingModelBuilder implements FormattingModelBuilderEx, C .after(COMMA).spaceIf(commonSettings.SPACE_AFTER_COMMA) .before(COMMA).spaceIf(commonSettings.SPACE_BEFORE_COMMA) .between(FROM_KEYWORD, DOT).spaces(1) + .between(DOT, IMPORT_KEYWORD).spaces(1) .around(DOT).spaces(0) .before(SEMICOLON).spaceIf(commonSettings.SPACE_BEFORE_SEMICOLON) .withinPairInside(LPAR, RPAR, ARGUMENT_LIST).spaceIf(commonSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES) diff --git a/python/testData/formatter/spaceAfterRelativeImport.py b/python/testData/formatter/spaceAfterRelativeImport.py new file mode 100644 index 000000000000..d163a992484b --- /dev/null +++ b/python/testData/formatter/spaceAfterRelativeImport.py @@ -0,0 +1 @@ +from . import x diff --git a/python/testData/formatter/spaceAfterRelativeImport_after.py b/python/testData/formatter/spaceAfterRelativeImport_after.py new file mode 100644 index 000000000000..d163a992484b --- /dev/null +++ b/python/testData/formatter/spaceAfterRelativeImport_after.py @@ -0,0 +1 @@ +from . import x diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index fde733c7a86c..45c004149522 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -191,6 +191,10 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + public void testSpaceAfterRelativeImport() { // PY-8112 + doTest(); + } + public void testPsiFormatting() { // IDEA-69724 String initial = "def method_name(\n" +