<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Apr 2, 2013 at 8:07 AM, Mark Dickinson <span dir="ltr"><<a href="mailto:dickinsm@gmail.com" target="_blank">dickinsm@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">
<div class="gmail_extra"><div class="gmail_quote"><div class="im">On Tue, Apr 2, 2013 at 1:44 AM, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">
<div class="gmail_extra"><div class="gmail_quote"><div>There's code in the slot wrappers so that if you return a non-int object from either __int__ or __index__, then the interpreter will complain about it, and if you return a subclass, it will be stripped back to just the base class.<br>
</div></div></div></div></blockquote></div><div class="im"><div><br></div></div><div>Can you point me to that code?  All I could find was PyLong_Check calls (I was looking for PyLong_CheckExact).</div></div></div></div></blockquote>
<div><br></div><div>And indeed:</div><div><br></div><div><div>iwasawa:Objects mdickinson$ /opt/local/bin/python3.3</div><div>Python 3.3.0 (default, Sep 29 2012, 08:16:19) </div><div>[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin</div>
<div>Type "help", "copyright", "credits" or "license" for more information.</div><div>>>> class A:</div><div>...     def __int__(self):</div><div>...         return True</div>
<div>...     def __index__(self):</div><div>...         return False</div><div>... </div><div>>>> a = A()</div><div>>>> int(a)</div><div>True</div><div>>>> import operator; operator.index(a)</div>
<div>False</div></div><div><br></div><div>Which means I have to do int(int(a)) to get the actual integer value.  Grr.</div><div><br></div><div>Mark</div><div><br></div></div></div></div>