diff --git a/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java b/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java index 3cc6dee169c2..b634f407b313 100644 --- a/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyRedundantParenthesesInspection.java @@ -23,6 +23,7 @@ import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.xmlb.SmartSerializer; import com.jetbrains.python.PyBundle; import com.jetbrains.python.PyTokenTypes; @@ -34,6 +35,8 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; +import static com.jetbrains.python.psi.PyUtil.as; + /** * User: catherine *

@@ -100,10 +103,15 @@ public class PyRedundantParenthesesInspection extends PyInspection { registerProblem(node, PyBundle.message("QFIX.redundant.parentheses"), new RedundantParenthesesQuickFix()); } else if (node.getParent() instanceof PyIfPart || - node.getParent() instanceof PyWhilePart || - node.getParent() instanceof PyReturnStatement) { + node.getParent() instanceof PyWhilePart) { registerProblem(node, PyBundle.message("QFIX.redundant.parentheses"), new RedundantParenthesesQuickFix()); } + else if (node.getParent() instanceof PyReturnStatement) { + final PyTupleExpression tuple = as(expression, PyTupleExpression.class); + if (!(tuple != null && ContainerUtil.or(tuple.getElements(), PyStarExpression.class::isInstance))) { + registerProblem(node, PyBundle.message("QFIX.redundant.parentheses"), new RedundantParenthesesQuickFix()); + } + } else if (expression instanceof PyBinaryExpression) { final PyBinaryExpression binaryExpression = (PyBinaryExpression)expression; diff --git a/python/testData/inspections/PyRedundantParenthesesInspection/Return.py b/python/testData/inspections/PyRedundantParenthesesInspection/Return.py new file mode 100644 index 000000000000..94267a5c237d --- /dev/null +++ b/python/testData/inspections/PyRedundantParenthesesInspection/Return.py @@ -0,0 +1,6 @@ +def f1(x): + return (x, *x) + + +def f2(x): + return (x, x) diff --git a/python/testSrc/com/jetbrains/python/inspections/PyRedundantParenthesesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyRedundantParenthesesInspectionTest.java index 1262822d0dfd..c91cb72016e5 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyRedundantParenthesesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyRedundantParenthesesInspectionTest.java @@ -78,4 +78,8 @@ public class PyRedundantParenthesesInspectionTest extends PyInspectionTestCase { doTest(); } + // PY-20324 + public void testReturn() { + runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + } }