fixed PY-6678 Assignment can be replace with augmented assignment: does nothing if there is a function in the assignment

This commit is contained in:
Ekaterina Tuzova
2012-06-20 18:46:23 +04:00
parent 7ed6a4371e
commit 20f7fc5e16
4 changed files with 18 additions and 3 deletions
@@ -63,9 +63,9 @@ public class AugmentedAssignmentQuickFix implements LocalQuickFix {
if ((leftExpression instanceof PyReferenceExpression || leftExpression instanceof PySubscriptionExpression)) {
if (leftExpression.getText().equals(targetText)) {
if (rightExpression instanceof PyNumericLiteralExpression || rightExpression instanceof PyStringLiteralExpression
|| rightExpression instanceof PyReferenceExpression || isPercentage(rightExpression) || isCompound(rightExpression)
|| isMathOperation(rightExpression, expression.getOperator())) {
if (rightExpression instanceof PyNumericLiteralExpression || rightExpression instanceof PyStringLiteralExpression ||
rightExpression instanceof PyCallExpression || rightExpression instanceof PyReferenceExpression
|| isPercentage(rightExpression) || isCompound(rightExpression) || isMathOperation(rightExpression, expression.getOperator())) {
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
final StringBuilder stringBuilder = new StringBuilder();
@@ -0,0 +1,5 @@
def retStr():
return ''
s1 = ''
<weak_warning descr="Assignment can be replaced with augmented assignment">s1 = s1 <caret>+ retStr()</weak_warning>
@@ -0,0 +1,5 @@
def retStr():
return ''
s1 = ''
s1 += retStr()
@@ -236,6 +236,11 @@ public class PyQuickFixTest extends PyTestCase {
PyBundle.message("QFIX.augment.assignment"), true, true);
}
public void testAugmentAssignmentFunction() { // PY-6678
doInspectionTest("AugmentAssignmentFunction.py", PyAugmentAssignmentInspection.class,
PyBundle.message("QFIX.augment.assignment"), true, true);
}
public void testChainedComparisons() { // PY-1020
doInspectionTest("ChainedComparisons.py", PyChainedComparisonsInspection.class,
PyBundle.message("QFIX.chained.comparison"), true, true);