From eb64521ae2e1ab78191044841827c69a13060472 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Wed, 14 Sep 2016 12:51:32 +0300 Subject: [PATCH] PY-20744 Python formatter is aware of variable annotations --- .../python/formatter/PythonFormattingModelBuilder.java | 2 ++ python/testData/formatter/variableAnnotations.py | 2 ++ python/testData/formatter/variableAnnotations_after.py | 2 ++ python/testSrc/com/jetbrains/python/PyFormatterTest.java | 4 ++++ 4 files changed, 10 insertions(+) create mode 100644 python/testData/formatter/variableAnnotations.py create mode 100644 python/testData/formatter/variableAnnotations_after.py diff --git a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java index 7e69b2dafb4d..bced7d4b8d23 100644 --- a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java +++ b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java @@ -95,6 +95,8 @@ public class PythonFormattingModelBuilder implements FormattingModelBuilderEx, C .betweenInside(MINUS, GT, ANNOTATION).none() .beforeInside(ANNOTATION, FUNCTION_DECLARATION).spaces(1) .beforeInside(ANNOTATION, NAMED_PARAMETER).none() + .beforeInside(ANNOTATION, TYPE_DECLARATION_STATEMENT).none() + .beforeInside(ANNOTATION, ASSIGNMENT_STATEMENT).none() .afterInside(COLON, ANNOTATION).spaces(1) .afterInside(RARROW, ANNOTATION).spaces(1) diff --git a/python/testData/formatter/variableAnnotations.py b/python/testData/formatter/variableAnnotations.py new file mode 100644 index 000000000000..cbf11a632768 --- /dev/null +++ b/python/testData/formatter/variableAnnotations.py @@ -0,0 +1,2 @@ +x : int +y : Optional[str] = 'foo' \ No newline at end of file diff --git a/python/testData/formatter/variableAnnotations_after.py b/python/testData/formatter/variableAnnotations_after.py new file mode 100644 index 000000000000..65670c87f0d6 --- /dev/null +++ b/python/testData/formatter/variableAnnotations_after.py @@ -0,0 +1,2 @@ +x: int +y: Optional[str] = 'foo' diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index c1a23e9e5a8f..5da55236a3a8 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -673,4 +673,8 @@ public class PyFormatterTest extends PyTestCase { getCommonCodeStyleSettings().SPACE_AFTER_COMMA = false; doTest(); } + + public void testVariableAnnotations() { + runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest); + } }