mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 11:53:49 +07:00
PY-31991 Formatter strips spaces around topmost expressions in f-strings fragments
Thus we forcibly remove them whenever they are added as a result of "Extract variable" refactoring. Probably we could add a dedicated formatter option for that in future.
This commit is contained in:
@@ -17,7 +17,6 @@ package com.jetbrains.python.formatter;
|
||||
|
||||
import com.intellij.formatting.*;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
@@ -113,6 +112,8 @@ public class PythonFormattingModelBuilder implements FormattingModelBuilderEx, C
|
||||
.between(COMMA, RBRACKET).spaceIf(commonSettings.SPACE_WITHIN_BRACKETS | commonSettings.SPACE_AFTER_COMMA)
|
||||
.withinPair(LBRACKET, RBRACKET).spaceIf(commonSettings.SPACE_WITHIN_BRACKETS)
|
||||
|
||||
.withinPair(FSTRING_FRAGMENT_START, FSTRING_FRAGMENT_END).spaces(0)
|
||||
|
||||
.before(COLON).spaceIf(pySettings.SPACE_BEFORE_PY_COLON)
|
||||
.afterInside(LPAR, FROM_IMPORT_STATEMENT).spaces(0, pySettings.FROM_IMPORT_NEW_LINE_AFTER_LEFT_PARENTHESIS)
|
||||
.betweenInside(COMMA, RPAR, FROM_IMPORT_STATEMENT).spaceIf(commonSettings.SPACE_AFTER_COMMA,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
s = f'foo{ 42 }bar'
|
||||
@@ -0,0 +1 @@
|
||||
s = f'foo{42}bar'
|
||||
@@ -0,0 +1,2 @@
|
||||
a = 42
|
||||
s = f'foo{a}bar'
|
||||
@@ -0,0 +1 @@
|
||||
s = f'foo{<selection>42</selection>}bar'
|
||||
@@ -928,6 +928,11 @@ public class PyFormatterTest extends PyTestCase {
|
||||
}
|
||||
|
||||
public void testMultilineFStringExpressions() {
|
||||
doTest();
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest);
|
||||
}
|
||||
|
||||
// PY-31991
|
||||
public void testSpacesAroundFStringFragmentExpressionStripped() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import com.jetbrains.python.PythonFileType;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.psi.PyCallExpression;
|
||||
import com.jetbrains.python.psi.PyExpression;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
@@ -315,6 +316,11 @@ public class PyIntroduceVariableTest extends PyIntroduceTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-31991
|
||||
public void testNoExtraSpacesAroundFStringFragmentExpression() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/refactoring/introduceVariable";
|
||||
|
||||
Reference in New Issue
Block a user