Fix PY-19748 'Replace with str.format method call' should not add u
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Thu, 8 Sep 2016 16:36:07 +0000 (19:36 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Wed, 28 Sep 2016 11:36:08 +0000 (14:36 +0300)
python/src/com/jetbrains/python/codeInsight/intentions/ConvertFormatOperatorToMethodIntention.java

index 1cc8e594829ea5c30a6d6e33ebe6563662c71949..647703486ab35c5735f5fccdf0bb5ecd03b26296 100644 (file)
@@ -45,6 +45,7 @@ import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import static com.jetbrains.python.psi.PyUtil.guessLanguageLevel;
 import static com.jetbrains.python.psi.PyUtil.sure;
 
 /**
@@ -257,7 +258,8 @@ public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction
     final TypeEvalContext context = TypeEvalContext.userInitiated(file.getProject(), file);
     final PyType rhsType = context.getType(rhs);
     String prefix = "";
-    if (PyTypeChecker.match(PyBuiltinCache.getInstance(rhs).getObjectType("unicode"), rhsType, context)) {
+    final LanguageLevel languageLevel = guessLanguageLevel(project);
+    if (!languageLevel.isPy3K() && PyTypeChecker.match(PyBuiltinCache.getInstance(rhs).getObjectType("unicode"), rhsType, context)) {
       prefix = "u";
     }
     final PyStringLiteralExpression leftExpression = (PyStringLiteralExpression)element.getLeftExpression();