fixed PY-9302 Class has no __init__ method: false positive for child class without one

This commit is contained in:
Ekaterina Tuzova
2013-04-09 19:31:19 +04:00
parent 0e0a670bd4
commit 1472b0eef6
3 changed files with 17 additions and 4 deletions
@@ -40,14 +40,14 @@ public class PyClassHasNoInitInspection extends PyInspection {
@Override
public void visitPyClass(PyClass node) {
final PyFunction init = node.findMethodByName(PyNames.INIT, false);
if (init == null) {
final PyFunction init = node.findInitOrNew(true);
if (init == null || PyNames.NEW.equals(init.getName())) {
registerProblem(node.getNameIdentifier(), PyBundle.message("INSP.class.has.no.init"),
new AddMethodQuickFix("__init__", new PyClassTypeImpl(node, false), false));
}
for (PyClass ancestor : node.iterateAncestorClasses()) {
final PyFunction ancestorInit = ancestor.findMethodByName(PyNames.INIT, false);
if (ancestorInit == null) {
final PyFunction ancestorInit = ancestor.findInitOrNew(false);
if (ancestorInit == null || PyNames.NEW.equals(ancestorInit.getName())) {
registerProblem(node.getNameIdentifier(), PyBundle.message("INSP.parent.$0.has.no.init", ancestor.getName()),
new AddMethodQuickFix("__init__", new PyClassTypeImpl(ancestor, false), false));
}
@@ -0,0 +1,9 @@
__author__ = 'ktisha'
class Base(object):
def __init__(self):
self.my = 1
class Child(Base): # <- Child class here should not be highlighted since
# it has init mehtod of Base class.
pass
@@ -19,6 +19,10 @@ public class PyClassHasNoInitInspectionTest extends PyTestCase {
doTest();
}
public void testInitInParentClass() {
doTest();
}
private void doTest() {
myFixture.configureByFile("inspections/PyClassHasNoInitInspection/" + getTestName(true) + ".py");
myFixture.enableInspections(PyClassHasNoInitInspection.class);