mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-9302 Class has no __init__ method: false positive for child class without one
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user