It's said that :
<blockquote>
<p>When it would yield a class method object, it is transformed into a
bound user-defined method object whose im_class and im_self attributes
are both C.</p>
</blockquote>
<p>in the <a href="http://docs.python.org/reference/datamodel.html" rel="nofollow">Reference</a></p>
<p>And I did an EX.</p>
<pre class="default prettyprint"><code><span class="pun">>>></span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> C</span><span class="pun">(</span><span class="kwd">object</span><span class="pun">)</span><span class="pln"> </span><span class="pun">:</span><span class="pln"><br>
</span><span class="pun">...</span><span class="pln"> </span><span class="lit">@classmethod</span><span class="pln"><br></span><span class="pun">...</span><span class="pln"> </span><span class="kwd">def</span><span class="pln"> cm</span><span class="pun">(</span><span class="pln">cls</span><span class="pun">)</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="kwd">print</span><span class="pln"> cls<br>
</span><span class="pun">...</span><span class="pln"> <br></span><span class="pun">>>></span><span class="pln"> C</span><span class="pun">.</span><span class="pln">cm<br></span><span class="pun"><</span><span class="pln">bound method type</span><span class="pun">.</span><span class="pln">cm of </span><span class="pun"><</span><span class="kwd">class</span><span class="pln"> </span><span class="str">'__main__.C'</span><span class="pun">>></span><span class="pln"><br>
</span><span class="pun">>>></span><span class="pln"> C</span><span class="pun">.</span><span class="pln">cm</span><span class="pun">.</span><span class="pln">im_self<br></span><span class="pun"><</span><span class="kwd">class</span><span class="pln"> </span><span class="str">'__main__.C'</span><span class="pun">></span><span class="pln"><br>
</span><span class="pun">>>></span><span class="pln"> C</span><span class="pun">.</span><span class="pln">cm</span><span class="pun">.</span><span class="pln">im_class<br></span><span class="pun"><</span><span class="pln">type </span><span class="str">'type'</span><span class="pun">></span><span class="pln"><br>
</span></code></pre>
<p>It's not hard for me to understand the result. <br></p><p>But unfortunately, in the reference, it's told that im_self should be <strong>the same</strong> as im_class. <br></p><p>And in my opinion , 'im_self' shold be C, but im_class is 'type' since C's metaclass is type. So they're obviously <b>not</b> 'both C'.<br>
</p>-- <br><div>[This information is automatically generated] </div>
<div><b>ted.sybil</b> aka. <b>ymfoi</b> aka. <b>Ted Yin</b></div><br>