Fix PY-20754 Supress 'Replace with str.format method call' for bytes
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Tue, 13 Sep 2016 15:40:26 +0000 (18:40 +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 647703486ab35c5735f5fccdf0bb5ecd03b26296..f3e2492c39b748dc8d6f9a1dc76892f68088c16e 100644 (file)
@@ -236,9 +236,13 @@ public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction
     if (languageLevel.isOlderThan(LanguageLevel.PYTHON26)) {
       return false;
     }
-    if (binaryExpression.getLeftExpression() instanceof PyStringLiteralExpression && binaryExpression.getOperator() == PyTokenTypes.PERC) {
-      setText(PyBundle.message("INTN.replace.with.method"));
-      return true;
+    if (binaryExpression.getLeftExpression() instanceof PyStringLiteralExpression 
+        && binaryExpression.getOperator() == PyTokenTypes.PERC) {
+      final PyStringLiteralExpression str = (PyStringLiteralExpression)binaryExpression.getLeftExpression();
+      if (!(str.getText().length() > 0 && Character.toUpperCase(str.getText().charAt(0)) == 'B')) {
+        setText(PyBundle.message("INTN.replace.with.method"));
+        return true;        
+      }
     }
     return false;
   }