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

Barry Warsaw barry at python.org
Wed Apr 3 19:46:49 CEST 2013

On Apr 04, 2013, at 03:04 AM, Steven D'Aprano wrote:

>On 04/04/13 01:16, Barry Warsaw wrote:

>> the other built-in types-as-functions, so int() calls __int__() which must
>> return a concrete integer.

>Why must it? I think that's the claim which must be justified, not just taken
>as a given.  When we call n = int(something), what's the use-case for caring
>that n is an instance of built-in int but not of a subclass, and is that
>use-case so compelling that it must be enforced for all uses of int() etc.?

It's a consistency-of-implementation issue.  Where built-in types are
callable, they return concrete instances of themselves.  This is true for
e.g. list, tuple, dict, bytes, str, and should also be true of int.


More information about the Python-Dev mailing list