From ded2dafba41f31fcd870b7ea80784a6e4ac49d72 Mon Sep 17 00:00:00 2001 From: Daniil Kalinin Date: Wed, 27 Apr 2022 11:39:05 +0300 Subject: [PATCH] PY-28496, PY-27660 Remove unnecessary Normal Indent which violates PEP8 codestyle rules in multiline call chains GitOrigin-RevId: 77e738367c33673c5c5f4b46472c3a49a5f64142 --- .../com/jetbrains/python/formatter/PyBlock.java | 2 +- ...gingIndentsInMultilineCallChainInParenthesis.py | 9 +++++++++ ...dentsInMultilineCallChainInParenthesis_after.py | 9 +++++++++ ...gIndentsInMultilineCallChainInSquareBrackets.py | 5 +++++ ...tsInMultilineCallChainInSquareBrackets_after.py | 5 +++++ .../multiLineCallChainSplitByBackslashes.py | 4 ++++ .../multiLineCallChainSplitByBackslashes_after.py | 4 ++++ .../com/jetbrains/python/PyFormatterTest.java | 14 ++++++++++++++ 8 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 python/testData/formatter/hangingIndentsInMultilineCallChainInParenthesis.py create mode 100644 python/testData/formatter/hangingIndentsInMultilineCallChainInParenthesis_after.py create mode 100644 python/testData/formatter/hangingIndentsInMultilineCallChainInSquareBrackets.py create mode 100644 python/testData/formatter/hangingIndentsInMultilineCallChainInSquareBrackets_after.py create mode 100644 python/testData/formatter/multiLineCallChainSplitByBackslashes.py create mode 100644 python/testData/formatter/multiLineCallChainSplitByBackslashes_after.py diff --git a/python/python-psi-impl/src/com/jetbrains/python/formatter/PyBlock.java b/python/python-psi-impl/src/com/jetbrains/python/formatter/PyBlock.java index c76d0d3558d4..51654e214e6b 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/python-psi-impl/src/com/jetbrains/python/formatter/PyBlock.java @@ -400,7 +400,7 @@ public class PyBlock implements ASTBlock { } else if (parentType == PyElementTypes.REFERENCE_EXPRESSION) { if (child != myNode.getFirstChildNode()) { - childIndent = Indent.getNormalIndent(); + childIndent = Indent.getNoneIndent(); if (hasLineBreaksBeforeInSameParent(child, 1)) { if (isInControlStatement()) { childIndent = Indent.getContinuationIndent(); diff --git a/python/testData/formatter/hangingIndentsInMultilineCallChainInParenthesis.py b/python/testData/formatter/hangingIndentsInMultilineCallChainInParenthesis.py new file mode 100644 index 000000000000..4c8467b81058 --- /dev/null +++ b/python/testData/formatter/hangingIndentsInMultilineCallChainInParenthesis.py @@ -0,0 +1,9 @@ +def get_queryset(self): + return ( + super().get_queryset() + .filter(user=self.request.user) + .prefetch_related( + 'lines__oscar_line', + 'lines__oscar_line__product' + ) + ) \ No newline at end of file diff --git a/python/testData/formatter/hangingIndentsInMultilineCallChainInParenthesis_after.py b/python/testData/formatter/hangingIndentsInMultilineCallChainInParenthesis_after.py new file mode 100644 index 000000000000..5a0fcdc864d5 --- /dev/null +++ b/python/testData/formatter/hangingIndentsInMultilineCallChainInParenthesis_after.py @@ -0,0 +1,9 @@ +def get_queryset(self): + return ( + super().get_queryset() + .filter(user=self.request.user) + .prefetch_related( + 'lines__oscar_line', + 'lines__oscar_line__product' + ) + ) diff --git a/python/testData/formatter/hangingIndentsInMultilineCallChainInSquareBrackets.py b/python/testData/formatter/hangingIndentsInMultilineCallChainInSquareBrackets.py new file mode 100644 index 000000000000..ef1eb6335071 --- /dev/null +++ b/python/testData/formatter/hangingIndentsInMultilineCallChainInSquareBrackets.py @@ -0,0 +1,5 @@ +c = ["line" + .casefold() + .capitalize() + .encode() +] \ No newline at end of file diff --git a/python/testData/formatter/hangingIndentsInMultilineCallChainInSquareBrackets_after.py b/python/testData/formatter/hangingIndentsInMultilineCallChainInSquareBrackets_after.py new file mode 100644 index 000000000000..52809d28e918 --- /dev/null +++ b/python/testData/formatter/hangingIndentsInMultilineCallChainInSquareBrackets_after.py @@ -0,0 +1,5 @@ +c = ["line" + .casefold() + .capitalize() + .encode() + ] diff --git a/python/testData/formatter/multiLineCallChainSplitByBackslashes.py b/python/testData/formatter/multiLineCallChainSplitByBackslashes.py new file mode 100644 index 000000000000..95b0398e4c5b --- /dev/null +++ b/python/testData/formatter/multiLineCallChainSplitByBackslashes.py @@ -0,0 +1,4 @@ +def func(): + return x.foo() \ + .bar() \ + .baz() \ No newline at end of file diff --git a/python/testData/formatter/multiLineCallChainSplitByBackslashes_after.py b/python/testData/formatter/multiLineCallChainSplitByBackslashes_after.py new file mode 100644 index 000000000000..0ca77d53b123 --- /dev/null +++ b/python/testData/formatter/multiLineCallChainSplitByBackslashes_after.py @@ -0,0 +1,4 @@ +def func(): + return x.foo() \ + .bar() \ + .baz() diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index 8845df941646..076b4f3ff2ca 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -1239,4 +1239,18 @@ public class PyFormatterTest extends PyTestCase { getCodeStyleSettings().setRightMargin(PythonLanguage.getInstance(), 20); doTest(); } + + // PY-28496 + public void testHangingIndentsInMultilineCallChainInParenthesis() { + doTest(); + } + + // PY-27660 + public void testHangingIndentsInMultilineCallChainInSquareBrackets() { + doTest(); + } + + public void testMultiLineCallChainSplitByBackslashes() { + doTest(); + } }