mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-24436 Fixed: False positive: "Class has not __init__ method" if A inherits B which inherits another A with __init__
Use type eval context in PyClassHasNoInitInspection while looking for __init__ or __new__ method
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -73,10 +73,10 @@ public class PyClassHasNoInitInspection extends PyInspection {
|
||||
if (!(type instanceof PyClassType)) return;
|
||||
}
|
||||
|
||||
final PyFunction init = node.findInitOrNew(true, null);
|
||||
final PyFunction init = node.findInitOrNew(true, myTypeEvalContext);
|
||||
if (init == null) {
|
||||
registerProblem(node.getNameIdentifier(), PyBundle.message("INSP.class.has.no.init"),
|
||||
new AddMethodQuickFix("__init__", node.getName(), false));
|
||||
new AddMethodQuickFix(PyNames.INIT, node.getName(), false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
from lib import Alice
|
||||
|
||||
|
||||
class Intermediary(Alice):
|
||||
pass
|
||||
|
||||
|
||||
class Alice(Intermediary):
|
||||
def __str__(self):
|
||||
return 'New Alice'
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class Alice:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __str__(self):
|
||||
return 'Old Alice'
|
||||
+16
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.jetbrains.python.inspections;
|
||||
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
|
||||
public class PyClassHasNoInitInspectionTest extends PyTestCase {
|
||||
|
||||
@@ -51,9 +52,23 @@ public class PyClassHasNoInitInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-24436
|
||||
public void testAInheritsBAndBInheritsImportedAWithDunderInit() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON30, this::doMultiFileTest);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile("inspections/PyClassHasNoInitInspection/" + getTestName(true) + ".py");
|
||||
myFixture.enableInspections(PyClassHasNoInitInspection.class);
|
||||
myFixture.checkHighlighting(false, false, true);
|
||||
}
|
||||
|
||||
private void doMultiFileTest() {
|
||||
final String folderPath = "inspections/PyClassHasNoInitInspection/" + getTestName(false) + "/";
|
||||
|
||||
myFixture.copyDirectoryToProject(folderPath, "");
|
||||
myFixture.configureFromTempProjectFile("a.py");
|
||||
myFixture.enableInspections(PyClassHasNoInitInspection.class);
|
||||
myFixture.checkHighlighting(false, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user