diff --git a/python/src/com/jetbrains/python/inspections/quickfix/RedundantParenthesesQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/RedundantParenthesesQuickFix.java index 7224cccbf4d9..3c4343420c54 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/RedundantParenthesesQuickFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/RedundantParenthesesQuickFix.java @@ -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; diff --git a/python/testData/inspections/RedundantParenthesesInTuples.py b/python/testData/inspections/RedundantParenthesesInTuples.py new file mode 100644 index 000000000000..668372db89b9 --- /dev/null +++ b/python/testData/inspections/RedundantParenthesesInTuples.py @@ -0,0 +1 @@ +print("%d%s%s" % (((1,) + ("", "")))) \ No newline at end of file diff --git a/python/testData/inspections/RedundantParenthesesInTuples_after.py b/python/testData/inspections/RedundantParenthesesInTuples_after.py new file mode 100644 index 000000000000..31ac4040ce02 --- /dev/null +++ b/python/testData/inspections/RedundantParenthesesInTuples_after.py @@ -0,0 +1 @@ +print("%d%s%s" % ((1,) + ("", ""))) \ 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 dded82dd8930..96deaf719141 100644 --- a/python/testSrc/com/jetbrains/python/PyQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/PyQuickFixTest.java @@ -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);