mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-10233 "Method may be static" should ignore method that have overrides
This commit is contained in:
@@ -10,6 +10,7 @@ import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.inspections.quickfix.PyMakeFunctionFromMethodQuickFix;
|
||||
import com.jetbrains.python.inspections.quickfix.PyMakeMethodStaticQuickFix;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.search.PyOverridingMethodsSearch;
|
||||
import com.jetbrains.python.psi.search.PySuperMethodsSearch;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -50,6 +51,8 @@ public class PyMethodMayBeStaticInspection extends PyInspection {
|
||||
if (containingClass == null) return;
|
||||
final Collection<PsiElement> supers = PySuperMethodsSearch.search(node).findAll();
|
||||
if (!supers.isEmpty()) return;
|
||||
final Collection<PyFunction> overrides = PyOverridingMethodsSearch.search(node, true).findAll();
|
||||
if (!overrides.isEmpty()) return;
|
||||
final PyDecoratorList decoratorList = node.getDecoratorList();
|
||||
if (decoratorList != null) {
|
||||
for (PyDecorator decorator : decoratorList.getDecorators()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class A:
|
||||
def <weak_warning descr="Method 'f' may be 'static'">f</weak_warning>(self, a):
|
||||
def f(self, a):
|
||||
print "A"
|
||||
|
||||
class B(A):
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class A:
|
||||
def f(self, a):
|
||||
print "A"
|
||||
|
||||
class B(A):
|
||||
def f(self, a):
|
||||
print self.b
|
||||
@@ -46,10 +46,15 @@ public class PyMethodMayBeStaticInspectionTest extends PyTestCase {
|
||||
public void testNotImplemented() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testOverwrittenMethod() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSuperMethod() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile("inspections/PyMethodMayBeStaticInspection/" + getTestName(true) + ".py");
|
||||
myFixture.enableInspections(PyMethodMayBeStaticInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user