PY-35624 Don't suggest renaming magic literals on expressions inside f-strings
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Sat, 8 Aug 2020 20:25:58 +0000 (23:25 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Mon, 10 Aug 2020 16:03:09 +0000 (16:03 +0000)
It's still quite dubious that this particular renamer is suggested for *any*
string literal in a Django project causing problems like PY-35808, but it will
be revised separately.

GitOrigin-RevId: d3346d4a4747d5db64d05c8e4465690dd46e1fb5

python/src/com/jetbrains/python/magicLiteral/PyMagicLiteralRenameHandler.java

index 4eb1b932d8c735c033225eee6f79820af38c5a41..a8f3194a20aecad20ac2cc1aa14c4c4a810bd239 100644 (file)
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiFile;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.refactoring.rename.RenameDialog;
 import com.intellij.refactoring.rename.RenameHandler;
+import com.jetbrains.python.psi.PyFStringFragment;
 import com.jetbrains.python.psi.PyStringLiteralExpression;
 import com.jetbrains.python.psi.StringLiteralExpression;
 import org.jetbrains.annotations.NotNull;
@@ -42,10 +43,7 @@ public final class PyMagicLiteralRenameHandler implements RenameHandler {
   @Nullable
   private static PsiElement getElement(PsiFile file, Editor editor) {
     PsiElement element = file.findElementAt(editor.getCaretModel().getCurrentCaret().getOffset());
-    if (element instanceof PyStringLiteralExpression) {
-      return element;
-    }
-    return PsiTreeUtil.getParentOfType(element, StringLiteralExpression.class);
+    return PsiTreeUtil.getParentOfType(element, StringLiteralExpression.class, false, PyFStringFragment.class);
   }
 
   @Override