fixed PY-9730 Method can be static: disable inspection for methods which simply raise NotImplementedError

This commit is contained in:
Ekaterina Tuzova
2013-05-09 20:19:19 +04:00
parent 0e5eed921c
commit 0c1ab3eb9d
4 changed files with 26 additions and 0 deletions
@@ -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);