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(); + } }