mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-9730 Method can be static: disable inspection for methods which simply raise NotImplementedError
This commit is contained in:
@@ -129,6 +129,8 @@ public class PyNames {
|
||||
|
||||
public static final String PYCACHE = "__pycache__";
|
||||
|
||||
public static final String NOT_IMPLEMENTED_ERROR = "NotImplementedError";
|
||||
|
||||
|
||||
/**
|
||||
* Contains all known predefined names of "__foo__" form.
|
||||
|
||||
@@ -78,12 +78,27 @@ public class PyMethodMayBeStaticInspection extends PyInspection {
|
||||
|
||||
final boolean[] mayBeStatic = {true};
|
||||
PyRecursiveElementVisitor visitor = new PyRecursiveElementVisitor() {
|
||||
@Override
|
||||
public void visitPyRaiseStatement(PyRaiseStatement node) {
|
||||
super.visitPyRaiseStatement(node);
|
||||
final PyExpression[] expressions = node.getExpressions();
|
||||
if (expressions.length == 1) {
|
||||
final PyExpression expression = expressions[0];
|
||||
if (expression instanceof PyCallExpression) {
|
||||
final PyExpression callee = ((PyCallExpression)expression).getCallee();
|
||||
if (callee != null && PyNames.NOT_IMPLEMENTED_ERROR.equals(callee.getText()))
|
||||
mayBeStatic[0] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyReferenceExpression(PyReferenceExpression node) {
|
||||
super.visitPyReferenceExpression(node);
|
||||
if (selfName.equals(node.getName())) {
|
||||
mayBeStatic[0] = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
__author__ = 'ktisha'
|
||||
|
||||
class A:
|
||||
def pop(self):
|
||||
raise NotImplementedError()
|
||||
@@ -43,6 +43,10 @@ public class PyMethodMayBeStaticInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotImplemented() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile("inspections/PyMethodMayBeStaticInspection/" + getTestName(true) + ".py");
|
||||
myFixture.enableInspections(PyMethodMayBeStaticInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user