mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-31795 Don't suggest removing parentheses when there is no expression inside
This commit is contained in:
@@ -82,8 +82,9 @@ public class PyRedundantParenthesesInspection extends PyInspection {
|
||||
|
||||
@Override
|
||||
public void visitPyParenthesizedExpression(final PyParenthesizedExpression node) {
|
||||
final PyExpression expression = node.getContainedExpression();
|
||||
if (node.textContains('\n')) return;
|
||||
final PyExpression expression = node.getContainedExpression();
|
||||
if (expression == null) return;
|
||||
final PyYieldExpression yieldExpression = PsiTreeUtil.getParentOfType(expression, PyYieldExpression.class, false);
|
||||
if (yieldExpression != null) return;
|
||||
if (expression instanceof PyTupleExpression && myIgnoreTupleInReturn) {
|
||||
|
||||
+4
-5
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyPsiUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -38,11 +39,9 @@ public class RedundantParenthesesQuickFix implements LocalQuickFix {
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (element instanceof PyParenthesizedExpression) {
|
||||
PyExpression expression = ((PyParenthesizedExpression)element).getContainedExpression();
|
||||
if (expression != null) {
|
||||
element = element.replace(expression);
|
||||
}
|
||||
final PyExpression content = PyPsiUtils.flattenParens((PyParenthesizedExpression)element);
|
||||
if (content != null) {
|
||||
element.replace(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
if <caret>(<EOLError descr="Indent expected"></EOLError><EOLError descr="')' expected"></EOLError>
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
def pycharm_hanger_method(a, b):
|
||||
if(<error descr="Unexpected expression syntax">!m_<caret>isReverse</error>)<error descr="Colon expected">{
|
||||
m_startPoint = startPoint
|
||||
} else {
|
||||
m_endPoint = startPoint
|
||||
}</error>
|
||||
@@ -0,0 +1 @@
|
||||
(<caret>((42)))
|
||||
@@ -0,0 +1 @@
|
||||
(42)
|
||||
@@ -248,6 +248,10 @@ public class PyQuickFixTest extends PyTestCase {
|
||||
doInspectionTest(PyRedundantParenthesesInspection.class, PyBundle.message("QFIX.redundant.parentheses"), true, true);
|
||||
}
|
||||
|
||||
public void testRedundantParenthesesMultipleParentheses() {
|
||||
doInspectionTest(PyRedundantParenthesesInspection.class, PyBundle.message("QFIX.redundant.parentheses"), true, true);
|
||||
}
|
||||
|
||||
// PY-15506
|
||||
public void testEmptyListOfBaseClasses() {
|
||||
doInspectionTest(PyRedundantParenthesesInspection.class, PyBundle.message("QFIX.redundant.parentheses"), true, true);
|
||||
|
||||
+10
@@ -78,6 +78,16 @@ public class PyRedundantParenthesesInspectionTest extends PyInspectionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-31795
|
||||
public void testSyntaxErrorInside() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-31795
|
||||
public void testSingleLeftParenthesis() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-20324
|
||||
public void testReturn() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest);
|
||||
|
||||
Reference in New Issue
Block a user