fixed PY-11500 False positive in method may be static inspection for decorated methods

This commit is contained in:
Ekaterina Tuzova
2013-11-28 18:32:27 +04:00
parent b2307d0d83
commit 184c578f63
3 changed files with 24 additions and 1 deletions

View File

@@ -70,7 +70,9 @@ public class PyMethodMayBeStaticInspection extends PyInspection {
if (!supers.isEmpty()) return;
final Collection<PyFunction> overrides = PyOverridingMethodsSearch.search(node, true).findAll();
if (!overrides.isEmpty()) return;
if (PyUtil.isDecoratedAsAbstract(node) || node.getModifier() != null) return;
final PyDecoratorList decoratorList = node.getDecoratorList();
if (decoratorList != null) return;
if (node.getModifier() != null) return;
final Property property = containingClass.findPropertyByCallable(node);
if (property != null) return;

View File

@@ -0,0 +1,15 @@
def bar(f):
def wrapper(self, *args, **kwargs):
print('running {cls}.{method}'.format(cls=type(self).__name__,
method=f.__name__))
return f(self, *args, **kwargs)
return wrapper
class C(object):
@bar
def foo(self): # False positive: self is used by @bar
return 'foo'
C().foo()

View File

@@ -15,6 +15,7 @@
*/
package com.jetbrains.python.inspections;
import com.intellij.testFramework.TestDataPath;
import com.jetbrains.python.PythonTestUtil;
import com.jetbrains.python.fixtures.PyTestCase;
@@ -23,6 +24,7 @@ import java.util.Arrays;
/**
* User: ktisha
*/
@TestDataPath("$CONTENT_ROOT/../testData/inspections/PyMethodMayBeStaticInspection/")
public class PyMethodMayBeStaticInspectionTest extends PyTestCase {
public void testTruePositive() {
@@ -65,6 +67,10 @@ public class PyMethodMayBeStaticInspectionTest extends PyTestCase {
doTest();
}
public void testDecorated() {
doTest();
}
public void testOverwrittenMethod() {
doTest();
}