diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 2ecbe90c9142..ccf4568daf2f 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -295,7 +295,7 @@ public class PyBlock implements ASTBlock { } } else if (parentType == PyElementTypes.STRING_LITERAL_EXPRESSION) { - if (PyTokenTypes.STRING_NODES.contains(childType)) { + if (PyTokenTypes.STRING_NODES.contains(childType) || childType == PyElementTypes.FSTRING_NODE) { childAlignment = getAlignmentForChildren(); } } diff --git a/python/testData/formatter/backslashGluedFStringNodesAlignment.py b/python/testData/formatter/backslashGluedFStringNodesAlignment.py new file mode 100644 index 000000000000..b315af57b608 --- /dev/null +++ b/python/testData/formatter/backslashGluedFStringNodesAlignment.py @@ -0,0 +1,2 @@ +string_literal = f'foo' \ + f'bar' diff --git a/python/testData/formatter/backslashGluedFStringNodesAlignment_after.py b/python/testData/formatter/backslashGluedFStringNodesAlignment_after.py new file mode 100644 index 000000000000..b315af57b608 --- /dev/null +++ b/python/testData/formatter/backslashGluedFStringNodesAlignment_after.py @@ -0,0 +1,2 @@ +string_literal = f'foo' \ + f'bar' diff --git a/python/testSrc/com/jetbrains/python/PyEditingTest.java b/python/testSrc/com/jetbrains/python/PyEditingTest.java index 09e785d8ffdb..4818774367ae 100644 --- a/python/testSrc/com/jetbrains/python/PyEditingTest.java +++ b/python/testSrc/com/jetbrains/python/PyEditingTest.java @@ -126,13 +126,13 @@ public class PyEditingTest extends PyTestCase { public void testEnterInFStringTextPart() { doTestEnter("f'foobar'", "f'foo' \\\n" + - " f'bar'"); + "f'bar'"); } // PY-31984 public void testEnterInFStringRightBeforeFragment() { doTestEnter("f'foo{42}bar'", "f'foo' \\\n" + - " f'{42}bar'"); + "f'{42}bar'"); } // PY-32918 diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index 58af8b40b506..f7e95a03452e 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -931,6 +931,11 @@ public class PyFormatterTest extends PyTestCase { runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest); } + // PY-33656 + public void testBackslashGluedFStringNodesAlignment() { + doTest(); + } + // PY-31991 public void testSpacesAroundFStringFragmentExpressionStripped() { runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest);