title: How does assignment of a function as a class attribute become a method in Python?
body: <pre><code>&gt;&gt;&gt; class A(object): pass
  &gt;&gt;&gt; def func(cls): pass
  &gt;&gt;&gt; A.func = func
  &gt;&gt;&gt; A.func
  &lt;unbound method A.func&gt;
  </code></pre>
  
  <p>How does this assignment create a method? It seems unintuitive that assignment does the following for classes:</p>
  
  <ul>
  <li>Turn functions into unbound instance methods</li>
  <li>Turn functions wrapped in <code>classmethod()</code> into class methods (actually, this is pretty intuitive)</li>
  <li>Turn functions wrapped in <code>staticmethod()</code> into functions</li>
  </ul>
  
  <p>It seems that for the first, there should be an <code>instancemethod()</code>, and for the last one, there shouldn't be a wrapper function at all. I understand that these are for uses within a <code>class</code> block, but why should they apply outside of it?</p>
  
  <p>But more importantly, how exactly does assignment of the function into a class work? What magic happens that resolves those 3 things?</p>
  
  <p>Even more confusing with this:</p>
  
  <pre><code>&gt;&gt;&gt; A.func
  &lt;unbound method A.func&gt;
  &gt;&gt;&gt; A.__dict__['func']
  &lt;function func at 0x...&gt;
  </code></pre>
  
  <p>But I think this is something to do with descriptors, when <em>retrieving</em> attributes. I don't think it has much to do with the <em>setting</em> of attributes here.</p>