PY-80844 Disable the intention for converting f-strings into t-strings in Python < 3.14

GitOrigin-RevId: 97162fca82d36958d61641c56315295329018304
This commit is contained in:
Mikhail Golubev
2025-05-02 16:01:53 +00:00
committed by intellij-monorepo-bot
parent 623f3c3482
commit 4ba9d71cce
3 changed files with 9 additions and 5 deletions
@@ -8,16 +8,15 @@ import com.intellij.modcommand.PsiUpdateModCommandAction
import com.intellij.openapi.editor.Document
import com.intellij.psi.util.parentOfType
import com.jetbrains.python.PyPsiBundle
import com.jetbrains.python.psi.PyDocStringOwner
import com.jetbrains.python.psi.PyFormattedStringElement
import com.jetbrains.python.psi.PyStringLiteralExpression
import com.jetbrains.python.psi.PyUtil
import com.jetbrains.python.psi.*
/**
* Intention to convert between f-strings and t-strings (PEP-750)
*/
class PyFStringToTStringIntention : PsiUpdateModCommandAction<PyFormattedStringElement>(PyFormattedStringElement::class.java) {
override fun getPresentation(context: ActionContext, stringElement: PyFormattedStringElement): Presentation? {
if (LanguageLevel.forElement(stringElement).isOlderThan(LanguageLevel.PYTHON314)) return null
val stringLiteral = stringElement.getParent() as? PyStringLiteralExpression ?: return null
val docStringOwner = stringLiteral.parentOfType<PyDocStringOwner>()
if (docStringOwner != null && docStringOwner.getDocStringExpression() === stringLiteral) return null
@@ -0,0 +1 @@
s = f"fo<caret>o"
@@ -40,6 +40,10 @@ public class PyFStringToTStringIntentionTest extends PyIntentionTestCase {
doFStringToTStringTest();
}
public void testNotAvailableBefore314() {
runWithLanguageLevel(LanguageLevel.PYTHON310, this::doNegativeTest);
}
private void doFStringToTStringTest() {
doTest(PyPsiBundle.message("INTN.convert.f.string.to.t.string"), LanguageLevel.getLatest());
}
@@ -49,6 +53,6 @@ public class PyFStringToTStringIntentionTest extends PyIntentionTestCase {
}
private void doNegativeTest() {
runWithLanguageLevel(LanguageLevel.getLatest(), () -> doNegativeTest(PyPsiBundle.message("INTN.convert.f.string.to.t.string")));
doNegativeTest(PyPsiBundle.message("INTN.convert.f.string.to.t.string"));
}
}