[Python-Dev] Semantics of __int__(), __index__()
dickinsm at gmail.com
Tue Apr 2 09:07:45 CEST 2013
On Tue, Apr 2, 2013 at 1:44 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> int() and operator.index() are both type coercion calls to produce true
> Python integers - they will never return a subclass, and this is both
> deliberate and consistent with all the other builtin types that accept an
> instance of themselves as input to the constructor.
That's good to hear.
> 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
Can you point me to that code? All I could find was PyLong_Check calls (I
was looking for PyLong_CheckExact).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev