From f29a1671f4fc95d29d7211bc7dd83f22969a9b0e Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Wed, 7 May 2014 12:32:22 +0400 Subject: [PATCH] fixed PY-12679 Remove redundant parenthesis: false negative for duplicated parenthesis in complicated and or statements --- .../python/inspections/PyRedundantParenthesesInspection.java | 3 +++ .../RedundantParenthesesParenthesizedExpression.py | 2 ++ .../RedundantParenthesesParenthesizedExpression_after.py | 2 ++ python/testSrc/com/jetbrains/python/PyQuickFixTest.java | 5 +++++ 4 files changed, 12 insertions(+) create mode 100644 python/testData/inspections/RedundantParenthesesParenthesizedExpression.py create mode 100644 python/testData/inspections/RedundantParenthesesParenthesizedExpression_after.py diff --git a/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java b/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java index c4f07120c9da..6d777b58535e 100644 --- a/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java @@ -108,6 +108,9 @@ public class PyRedundantParenthesesInspection extends PyInspection { } } } + else if (expression instanceof PyParenthesizedExpression) { + registerProblem(expression, "Remove redundant parentheses", new RedundantParenthesesQuickFix()); + } } } diff --git a/python/testData/inspections/RedundantParenthesesParenthesizedExpression.py b/python/testData/inspections/RedundantParenthesesParenthesizedExpression.py new file mode 100644 index 000000000000..c068255430ee --- /dev/null +++ b/python/testData/inspections/RedundantParenthesesParenthesizedExpression.py @@ -0,0 +1,2 @@ +if ((1 and 2 == 'left')) or (3): + pass \ No newline at end of file diff --git a/python/testData/inspections/RedundantParenthesesParenthesizedExpression_after.py b/python/testData/inspections/RedundantParenthesesParenthesizedExpression_after.py new file mode 100644 index 000000000000..0c201277ddeb --- /dev/null +++ b/python/testData/inspections/RedundantParenthesesParenthesizedExpression_after.py @@ -0,0 +1,2 @@ +if (1 and 2 == 'left') or (3): + pass \ 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 2f5d1f790a2d..fde0c2e6c008 100644 --- a/python/testSrc/com/jetbrains/python/PyQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/PyQuickFixTest.java @@ -205,6 +205,11 @@ public class PyQuickFixTest extends PyTestCase { PyBundle.message("QFIX.redundant.parentheses"), true, true); } + public void testRedundantParenthesesParenthesizedExpression() { // PY-12679 + doInspectionTest("RedundantParenthesesParenthesizedExpression.py", PyRedundantParenthesesInspection.class, + PyBundle.message("QFIX.redundant.parentheses"), true, true); + } + public void testChainedComparisons() { // PY-1020 doInspectionTest("ChainedComparisons.py", PyChainedComparisonsInspection.class, PyBundle.message("QFIX.chained.comparison"), true, true);