Suppress highlighting empty raise without exception to re-raise in functions (PY-27232)

This commit is contained in:
Semyon Proshev
2018-11-30 20:03:42 +03:00
parent 2720a30578
commit d1e55f1978
3 changed files with 15 additions and 6 deletions
@@ -3,10 +3,7 @@ package com.jetbrains.python.validation;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.psi.PyExceptPart;
import com.jetbrains.python.psi.PyFinallyPart;
import com.jetbrains.python.psi.PyRaiseStatement;
import com.jetbrains.python.psi.PyTryExceptStatement;
import com.jetbrains.python.psi.*;
/**
* Marks misplaced default 'except' clauses.
@@ -30,7 +27,8 @@ public class TryExceptAnnotator extends PyAnnotator {
@Override
public void visitPyRaiseStatement(PyRaiseStatement node) {
if (node.getExpressions().length == 0 && PsiTreeUtil.getParentOfType(node, PyExceptPart.class, PyFinallyPart.class) == null) {
if (node.getExpressions().length == 0 &&
PsiTreeUtil.getParentOfType(node, PyExceptPart.class, PyFinallyPart.class, PyFunction.class) == null) {
markError(node, "No exception to reraise");
}
}
+7 -1
View File
@@ -9,4 +9,10 @@ except:
try:
raise ValueError
finally:
<error descr="Python version 2.7 does not support this syntax. Raise with no arguments can only be used in an except block">raise</error>
<error descr="Python version 2.7 does not support this syntax. Raise with no arguments can only be used in an except block">raise</error>
def exception_handler():
if undefined:
raise
log_somehow()
@@ -24,4 +24,9 @@ try:
pass
except:
raise
def exception_handler():
if undefined:
raise
log_somehow()