[Python-Dev] Semantics of __int__(), __index__()

Terry Jan Reedy tjreedy at udel.edu
Thu Apr 4 04:18:57 CEST 2013

On 4/3/2013 3:36 PM, Ethan Furman wrote:
> On 04/03/2013 12:21 PM, Tres Seaver wrote:

>> Given that requirement, we still don't have to mandate that __int__
>> return an actual instance of the int type:  the coercion could happen
>> inside int() (as it would for any non-subclass).
> I don't understand.  A non-int could only become an int via __int__,
> which int() calls.  What magic is there in int() to turn any arbitrary
> object into an integer?

 From the 2.7 manual:
Called to implement the built-in functions complex(), int(), long(), and 
float(). Should return a value of the appropriate type."

I have always understood 'value of the appropriate type' to mean just 
what Guido says he intended it to mean. Changing to 'instance of the 
class or subclass thereof' is a change.

More information about the Python-Dev mailing list