title: Get defining class of unbound method object in Python 3
body: <p>Say I want to make a decorator for methods defined in a class. I want that decorator, when invoked, to be able to set an attribute on the class defining the method (in order to register it in a list of methods that serve a particular purpose).</p>
  
  <p>In Python 2, the <code>im_class</code> method accomplishes this nicely:</p>
  
  <pre><code>def decorator(method):
    cls = method.im_class
    cls.foo = 'bar'
    return method
  </code></pre>
  
  <p>However, in Python 3, no such attribute (or a  replacement for it) seems to exist. I suppose the idea was that you could call <code>type(method.__self__)</code> to get the class, but this does not work for unbound methods, since <code>__self__ == None</code> in that case.</p>
  
  <p><strong>NOTE:</strong> This question is actually a bit irrelevant for my case, since I've chosen instead to set an attribute on the method itself and then have the instance scan through all of its methods looking for that attribute at the appropriate time. I am also (currently) using Python 2.6. However, I am curious if there is any replacement for the version 2 functionality, and if not, what the rationale was for removing it completely.</p>
  
  <p><strong>EDIT</strong>: I just found <a href="https://stackoverflow.com/questions/2188409/how-to-find-class-of-bound-method-during-class-construction-in-python-3-1">this question</a>. This makes it seem like the best solution is just to avoid it like I have. I'm still wondering why it was removed though.</p>