title: Adding attributes to instancemethods in Python
body: <p>I bumped into this behaviour when trying to get class-decorators and method-decorators to play nicely together. Essentially, the method decorators would flag some of the methods as special with some dummy value, and the class decorator would come by after and fill in the value later. This is a simplified example</p>
  
  <pre><code>&gt;&gt;&gt; class cow:
  &gt;&gt;&gt;     def moo(self):
  &gt;&gt;&gt;         print 'mooo'
  &gt;&gt;&gt;     moo.thing = 10
  &gt;&gt;&gt;
  &gt;&gt;&gt; cow.moo.thing
  10
  &gt;&gt;&gt; cow().moo.thing
  10
  &gt;&gt;&gt; cow.moo.thing = 5
  AttributeError: 'instancemethod' object has no attribute 'thing'
  &gt;&gt;&gt; cow().moo.thing = 5
  AttributeError: 'instancemethod' object has no attribute 'thing'
  &gt;&gt;&gt; cow.moo.__func__.thing = 5
  &gt;&gt;&gt; cow.moo.thing 
  5
  </code></pre>
  
  <p>Does anyone know why <code>cow.moo.thing = 5</code> does not work, even though <code>cow.moo.thing</code> quite clearly gives me 10? And why <code>cow.moo.__func__.thing = 5</code> works? I have no idea why it does, but in randomly fiddling with stuff in the <code>dir(cow.moo)</code> list trying to get something to work it suddenly did, and i have no idea why.</p>