mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-63319 Fix inverting comparisons in conditions when the left operand doesn't belong to a chained comparison
GitOrigin-RevId: 75b988b6c53bd15d0001ede1f2ebc71153b1de5b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e2f2b2da6d
commit
ecfced5e8f
@@ -207,7 +207,7 @@ private fun getInvertedConditionExpression(
|
||||
val chainedExpressions = mutableListOf<PyExpression>()
|
||||
var currentExpression = expression
|
||||
while (currentExpression is PyBinaryExpression && comparisonStrings.containsKey(currentExpression.operator)) {
|
||||
val leftExpression = (currentExpression.leftExpression as? PyBinaryExpression)?.rightExpression
|
||||
val leftExpression = (currentExpression.leftExpression as? PyBinaryExpression)?.takeIf { comparisonStrings.containsKey(it.operator) }?.rightExpression
|
||||
?: currentExpression.leftExpression
|
||||
val invertedOperator = invertedComparisons.getValue(currentExpression.operator)
|
||||
val invertedExpression = generator.createBinaryExpression(
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
def func():
|
||||
<caret>if 4 - 3 == 1:
|
||||
print("hi")
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
def func():
|
||||
if 4 - 3 != 1:
|
||||
return
|
||||
print("hi")
|
||||
@@ -495,6 +495,11 @@ class PyInvertIfConditionIntentionTest : PyIntentionTestCase() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
// PY-63319
|
||||
fun testNonChainableBinaryExpressionAsComparisonLeftOperand() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
private fun doTest() {
|
||||
doIntentionTest(PyPsiBundle.message("INTN.invert.if.condition"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user