PY-18203 Redundant parentheses quick fix produces syntactically incorrect code for tuples

If parentheses expression contains binary expression where left and right are parentheses expressions too, we check if left and right contain tuples
This commit is contained in:
Valentina Kiryushkina
2016-01-14 17:46:28 +03:00
parent 1e2e2f77d3
commit 05253be08a
4 changed files with 9 additions and 1 deletions
@@ -72,7 +72,8 @@ public class RedundantParenthesesQuickFix implements LocalQuickFix {
right instanceof PyParenthesizedExpression) {
PyExpression leftContained = ((PyParenthesizedExpression)left).getContainedExpression();
PyExpression rightContained = ((PyParenthesizedExpression)right).getContainedExpression();
if (leftContained != null && rightContained != null) {
if (leftContained != null && rightContained != null &&
!(leftContained instanceof PyTupleExpression) && !(rightContained instanceof PyTupleExpression)) {
left.replace(leftContained);
right.replace(rightContained);
return true;
@@ -0,0 +1 @@
print("%d%s%s" % (((1,) + <caret>("", ""))))
@@ -0,0 +1 @@
print("%d%s%s" % ((1,) + ("", "")))
@@ -244,6 +244,11 @@ public class PyQuickFixTest extends PyTestCase {
doInspectionTest(PyRedundantParenthesesInspection.class, PyBundle.message("QFIX.redundant.parentheses"), true, true);
}
// PY-18203
public void testRedundantParenthesesInTuples() {
doInspectionTest(PyRedundantParenthesesInspection.class, PyBundle.message("QFIX.redundant.parentheses"), true, true);
}
// PY-1020
public void testChainedComparisons() {
doInspectionTest(PyChainedComparisonsInspection.class, PyBundle.message("QFIX.chained.comparison"), true, true);