From ff1bb21ba8a517f9f5e6b8d2c3b6dc5b10633f2b Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Thu, 20 Dec 2018 23:07:21 +0700 Subject: [PATCH] PY-33266 Don't show duplicate and nested warnings about redundant parentheses We could duplicate them because in case like ((42)) we used to show one warning for (42) as for parenthesized expression inside another one and another warning for (42) as for parenthesized expression containing a literal expression. --- .../inspections/PyRedundantParenthesesInspection.java | 1 + .../PyRedundantParenthesesInspection/NestedParentheses.py | 1 + .../inspections/PyRedundantParenthesesInspectionTest.java | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 python/testData/inspections/PyRedundantParenthesesInspection/NestedParentheses.py diff --git a/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java b/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java index e2b622c6cd18..fb793233f4ad 100644 --- a/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java @@ -83,6 +83,7 @@ public class PyRedundantParenthesesInspection extends PyInspection { @Override public void visitPyParenthesizedExpression(final PyParenthesizedExpression node) { if (node.textContains('\n')) return; + if (node.getParent() instanceof PyParenthesizedExpression) return; final PyExpression expression = node.getContainedExpression(); if (expression == null) return; final PyYieldExpression yieldExpression = PsiTreeUtil.getParentOfType(expression, PyYieldExpression.class, false); diff --git a/python/testData/inspections/PyRedundantParenthesesInspection/NestedParentheses.py b/python/testData/inspections/PyRedundantParenthesesInspection/NestedParentheses.py new file mode 100644 index 000000000000..a2e8576c830f --- /dev/null +++ b/python/testData/inspections/PyRedundantParenthesesInspection/NestedParentheses.py @@ -0,0 +1 @@ +x = (((42))) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/PyRedundantParenthesesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyRedundantParenthesesInspectionTest.java index 7b3459ac69c5..43d427ceb2bf 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyRedundantParenthesesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyRedundantParenthesesInspectionTest.java @@ -15,7 +15,6 @@ */ package com.jetbrains.python.inspections; -import com.intellij.testFramework.ExpectedHighlightingData; import com.jetbrains.python.fixtures.PyInspectionTestCase; import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.NotNull; @@ -56,7 +55,7 @@ public class PyRedundantParenthesesInspectionTest extends PyInspectionTestCase { } public void testTryExcept() { - ExpectedHighlightingData.expectedDuplicatedHighlighting(this::doTest); + doTest(); } public void testTryExceptNegate() { @@ -93,4 +92,9 @@ public class PyRedundantParenthesesInspectionTest extends PyInspectionTestCase { public void testReturn() { runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); } + + // PY-33266 + public void testNestedParentheses() { + doTest(); + } }