fixed PY-11500 False positive in method may be static inspection for decorated methods
authorEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Thu, 28 Nov 2013 14:32:27 +0000 (18:32 +0400)
committerEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Thu, 28 Nov 2013 14:32:27 +0000 (18:32 +0400)
python/src/com/jetbrains/python/inspections/PyMethodMayBeStaticInspection.java
python/testData/inspections/PyMethodMayBeStaticInspection/decorated.py [new file with mode: 0644]
python/testSrc/com/jetbrains/python/inspections/PyMethodMayBeStaticInspectionTest.java

index 2bc6424a5b6c4fc2d93db7abdb9675999be68adb..71f2772dae08aa5a9ea494294f7124257c4620cb 100644 (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;
 
diff --git a/python/testData/inspections/PyMethodMayBeStaticInspection/decorated.py b/python/testData/inspections/PyMethodMayBeStaticInspection/decorated.py
new file mode 100644 (file)
index 0000000..c16da1e
--- /dev/null
@@ -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()
\ No newline at end of file
index ea40830d38dc9bb169324dfd41665d4efbb096fa..885f0430ae7374d3000e7b6370c4bced59f31670 100644 (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();
   }