diff --git a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/intentions/PyFStringToTStringIntention.kt b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/intentions/PyFStringToTStringIntention.kt index 7223cdc17134..d5c5f1e9fa3d 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/intentions/PyFStringToTStringIntention.kt +++ b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/intentions/PyFStringToTStringIntention.kt @@ -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::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() if (docStringOwner != null && docStringOwner.getDocStringExpression() === stringLiteral) return null diff --git a/python/testData/intentions/PyFStringToTStringIntentionTest/notAvailableBefore314.py b/python/testData/intentions/PyFStringToTStringIntentionTest/notAvailableBefore314.py new file mode 100644 index 000000000000..8db3005d3b7a --- /dev/null +++ b/python/testData/intentions/PyFStringToTStringIntentionTest/notAvailableBefore314.py @@ -0,0 +1 @@ +s = f"foo" \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/intentions/PyFStringToTStringIntentionTest.java b/python/testSrc/com/jetbrains/python/intentions/PyFStringToTStringIntentionTest.java index 7acd858c89ac..77e3c2c22560 100644 --- a/python/testSrc/com/jetbrains/python/intentions/PyFStringToTStringIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/intentions/PyFStringToTStringIntentionTest.java @@ -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")); } }