PY-19998 Properly detect constant in the middle for the left operand of the left...
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Thu, 7 Jul 2016 12:49:15 +0000 (15:49 +0300)
committerMikhail Golubev <mikhail.golubev@jetbrains.com>
Mon, 11 Jul 2016 10:56:06 +0000 (13:56 +0300)
python/src/com/jetbrains/python/inspections/PyChainedComparisonsInspection.java
python/testData/inspections/PyChainedComparisonsInspectionWithConstantInTheMiddle/test.py

index 2d9fd8d0c4f2b1b149ce5ac450f319d775eb43ab..3e9752bd0629473332d59516d2b966a486caf0b7 100644 (file)
  */
 package com.jetbrains.python.inspections;
 
-import com.intellij.codeInspection.*;
+import com.intellij.codeInspection.LocalInspectionToolSession;
+import com.intellij.codeInspection.LocalQuickFix;
+import com.intellij.codeInspection.ProblemDescriptor;
+import com.intellij.codeInspection.ProblemsHolder;
 import com.intellij.openapi.project.Project;
 import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
 import com.intellij.psi.PsiElementVisitor;
 import com.intellij.psi.PsiFile;
-import com.intellij.util.Consumer;
 import com.intellij.util.ui.CheckBox;
 import com.jetbrains.python.PyBundle;
 import com.jetbrains.python.PyTokenTypes;
@@ -191,14 +193,14 @@ public class PyChainedComparisonsInspection extends PyInspection {
           if (leftLeft.getText().equals(getLeftExpression(rightExpression, false).getText())) {
             myIsLeft = true;
             myIsRight = true;
-            isConstantInTheMiddle = leftRight instanceof PyLiteralExpression;
+            isConstantInTheMiddle = leftLeft instanceof PyLiteralExpression;
             return true;
           }
           final PyExpression right = getSmallestRight(rightExpression, false);
           if (right != null && leftLeft.getText().equals(right.getText())) {
             myIsLeft = true;
             myIsRight = false;
-            isConstantInTheMiddle = leftRight instanceof PyLiteralExpression;
+            isConstantInTheMiddle = leftLeft instanceof PyLiteralExpression;
             return true;
           }
         }
index 528cf139bbeb40defe6d8ab5676c7da1bb0c5e48..f070156ea2998451a90b7b87fcd653924159ce1f 100644 (file)
@@ -1,4 +1,9 @@
 # PY-16397
 x, y = 2, 3
 if x > 0 and y < 0:
-    pass
\ No newline at end of file
+    pass
+
+
+# PY-19998
+<weak_warning descr="Simplify chained comparison">x > 1 and x < 2</weak_warning>
+1 < x and 1 > y