mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-20324 Don't report parentheses around returned tuples with unpacking
This commit is contained in:
@@ -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
|
||||
* <p>
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
def f1(x):
|
||||
return (x, *x)
|
||||
|
||||
|
||||
def f2(x):
|
||||
return <weak_warning descr="Remove redundant parentheses">(x, x)</weak_warning>
|
||||
+4
@@ -78,4 +78,8 @@ public class PyRedundantParenthesesInspectionTest extends PyInspectionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-20324
|
||||
public void testReturn() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user