title: Callable object decorator applied to method doesn't get self argument on input
body: <pre><code>import functools
  
  
  class Decor(object):
      def __init__(self, func):
           self.func = func
  
      def __call__(self, *args, **kwargs):
          def closure(*args, **kwargs):
              print args, kwargs
              return self.func(*args, **kwargs)
          return closure(*args, **kwargs)
  
  
  class Victim(object):
      @Decor
      def sum(self, a, b):
          return a+b
  
  
  v = Victim()
  v.sum(1, 2)
  </code></pre>
  
  <p>Results in:</p>
  
  <pre><code>(1, 2) {}
  Traceback (most recent call last):
    File "test.py", line 19, in &lt;module&gt;
      v.sum(1, 2)
    File "test.py", line 11, in __call__
      return closure(*args, **kwargs)
    File "test.py", line 10, in closure
      return self.func(*args, **kwargs)
  TypeError: sum() takes exactly 3 arguments (2 given)
  </code></pre>
  
  <p>How do I get <code>self</code> argument for the method?</p>
  
  <p><strong>UPDATE:</strong>
  I've managed to create a more useful adaptation of Martijn's answer, which returns <code>Decor</code> object in response to <code>__get__</code>, but at the same time binds <code>self</code> argument, when it is called as a method of object. With this version you can say e.g. <code>Victim.sum.hooks.append(my_favorite_function)</code> and <code>my_favorite_function</code> will be called before <code>Victim.sum</code>. <strong>WARNING</strong>: this version is <strong>thread-unsafe</strong>.</p>
  
  <pre><code>class Decor(object):
      def __init__(self, func):
          self.func = func
          self.hooks = []
          wraps(self.func)(self)
  
      def __get__(self, instance, klass):
          if instance != None: self.instance = instance
          if klass != None: self.klass = klass
          return self
  
      def __call__(self, *args, **kwargs):
          def closure(*args, **kwargs):
             for function in self.hooks:
                 function(*args, **kwargs)
             func = self.func
             retval = func(*args, **kwargs) #kwargs_copy #called with notify = False
             return retval
          return closure.__get__(self.instance, self.klass)(*args, **kwargs)
  </code></pre>