From 20f7fc5e16ad3682fb474dba0fb479cc92948e76 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Wed, 20 Jun 2012 18:46:23 +0400 Subject: [PATCH] fixed PY-6678 Assignment can be replace with augmented assignment: does nothing if there is a function in the assignment --- .../python/actions/AugmentedAssignmentQuickFix.java | 6 +++--- python/testData/inspections/AugmentAssignmentFunction.py | 5 +++++ .../testData/inspections/AugmentAssignmentFunction_after.py | 5 +++++ python/testSrc/com/jetbrains/python/PyQuickFixTest.java | 5 +++++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 python/testData/inspections/AugmentAssignmentFunction.py create mode 100644 python/testData/inspections/AugmentAssignmentFunction_after.py diff --git a/python/src/com/jetbrains/python/actions/AugmentedAssignmentQuickFix.java b/python/src/com/jetbrains/python/actions/AugmentedAssignmentQuickFix.java index db5fa99a26e6..c0be076c60d9 100644 --- a/python/src/com/jetbrains/python/actions/AugmentedAssignmentQuickFix.java +++ b/python/src/com/jetbrains/python/actions/AugmentedAssignmentQuickFix.java @@ -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(); diff --git a/python/testData/inspections/AugmentAssignmentFunction.py b/python/testData/inspections/AugmentAssignmentFunction.py new file mode 100644 index 000000000000..413f876acce6 --- /dev/null +++ b/python/testData/inspections/AugmentAssignmentFunction.py @@ -0,0 +1,5 @@ +def retStr(): + return '' + +s1 = '' +s1 = s1 + retStr() \ No newline at end of file diff --git a/python/testData/inspections/AugmentAssignmentFunction_after.py b/python/testData/inspections/AugmentAssignmentFunction_after.py new file mode 100644 index 000000000000..815ffd292e6b --- /dev/null +++ b/python/testData/inspections/AugmentAssignmentFunction_after.py @@ -0,0 +1,5 @@ +def retStr(): + return '' + +s1 = '' +s1 += retStr() \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyQuickFixTest.java b/python/testSrc/com/jetbrains/python/PyQuickFixTest.java index 47aa2d7bd9a2..8b2c34165ec1 100644 --- a/python/testSrc/com/jetbrains/python/PyQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/PyQuickFixTest.java @@ -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);