title: Can a decorator of an instance method access the class?
body: <p>I have something roughly like the following. Basically I need to access the class of an instance method from a decorator used upon the instance method in its definition.</p>
  <pre class="lang-py prettyprint-override"><code>def decorator(view):
      # do something that requires view's class
      print view.im_class
      return view
  
  class ModelA(object):
      @decorator
      def a_method(self):
          # do some stuff
          pass
  </code></pre>
  <p>The code as-is gives:</p>
  <blockquote>
  <p>AttributeError: 'function' object has no attribute 'im_class'</p>
  </blockquote>
  <p>I found similar question/answers - <a href="https://stackoverflow.com/questions/306130/">Python decorator makes function forget that it belongs to a class</a> and <a href="https://stackoverflow.com/questions/2309124">Get class in Python decorator</a> - but these rely upon a workaround that grabs the instance at run-time by snatching the first parameter.  In my case, I will be calling the method based upon the information gleaned from its class, so I can't wait for a call to come in.</p>