fixed PY-9408 Method can be static: handle properties and classmethods friendlier

This commit is contained in:
Ekaterina Tuzova
2013-04-10 18:39:29 +04:00
parent 24e519827e
commit 9ccbc0852a
4 changed files with 39 additions and 1 deletions
@@ -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);