diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 4c58ebfbe928..1b03c9f26b2c 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -407,6 +407,10 @@ public class PyBlock implements ASTBlock { final PyExpression valueExpression = ((PyKeywordArgument)firstItem).getValueExpression(); return valueExpression != null && hasHangingIndent(valueExpression); } + else if (firstItem instanceof PyKeyValueExpression) { + final PyExpression value = ((PyKeyValueExpression)firstItem).getValue(); + return value != null && hasHangingIndent(value); + } return hasHangingIndent(firstItem); } } diff --git a/python/testData/formatter/hangingIndentInKeyValuePair.py b/python/testData/formatter/hangingIndentInKeyValuePair.py new file mode 100644 index 000000000000..7dff24698bf9 --- /dev/null +++ b/python/testData/formatter/hangingIndentInKeyValuePair.py @@ -0,0 +1,5 @@ +example = {'breakfast': { + 'eggs': 1, + 'spam': 2 + } + } \ No newline at end of file diff --git a/python/testData/formatter/hangingIndentInKeyValuePair_after.py b/python/testData/formatter/hangingIndentInKeyValuePair_after.py new file mode 100644 index 000000000000..057ebe6a340d --- /dev/null +++ b/python/testData/formatter/hangingIndentInKeyValuePair_after.py @@ -0,0 +1,5 @@ +example = {'breakfast': { + 'eggs': 1, + 'spam': 2 +} +} \ 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 37ade21b235c..dc04d530f20b 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -559,6 +559,11 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + // PY-15171 + public void testHangingIndentInKeyValuePair() { + doTest(); + } + public void testAlignmentOfEmptyCollectionLiterals() { doTest(); }