mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-9408 Method can be static: handle properties and classmethods friendlier
This commit is contained in:
@@ -49,8 +49,12 @@ public class PyMethodMayBeStaticInspection extends PyInspection {
|
||||
final PyDecoratorList decoratorList = node.getDecoratorList();
|
||||
if (decoratorList != null) {
|
||||
for (PyDecorator decorator : decoratorList.getDecorators()) {
|
||||
if (PyNames.STATICMETHOD.equals(decorator.getName()))
|
||||
final String decoratorName = decorator.getName();
|
||||
if (PyNames.STATICMETHOD.equals(decoratorName) || PyNames.CLASSMETHOD.equals(decoratorName)) {
|
||||
return;
|
||||
}
|
||||
final Property property = containingClass.findPropertyByCallable(node);
|
||||
if (property != null) return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
__author__ = 'ktisha'
|
||||
|
||||
class A():
|
||||
|
||||
@classmethod
|
||||
def my_method(cls):
|
||||
print 1
|
||||
@@ -0,0 +1,19 @@
|
||||
__author__ = 'ktisha'
|
||||
|
||||
class C(object):
|
||||
def __init__(self):
|
||||
self._x = None
|
||||
|
||||
@property
|
||||
def x(self):
|
||||
"""I'm the 'x' property."""
|
||||
return "property"
|
||||
|
||||
@x.setter
|
||||
def x(self, value):
|
||||
print "setter"
|
||||
|
||||
@x.deleter
|
||||
def x(self):
|
||||
print "deleter"
|
||||
|
||||
@@ -31,6 +31,14 @@ public class PyMethodMayBeStaticInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testClassMethod() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testProperty() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile("inspections/PyMethodMayBeStaticInspection/" + getTestName(true) + ".py");
|
||||
myFixture.enableInspections(PyMethodMayBeStaticInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user