[Python-Dev] Semantics of int(), index() (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Wed Apr 3 17:41:59 CEST 2013


Le Wed, 03 Apr 2013 08:21:22 -0700, Ethan Furman <ethan at stoneleaf.us> a écrit :

On 04/03/2013 08:14 AM, Nick Coghlan wrote: > > On 4 Apr 2013 00:18, "Barry Warsaw" <barry at python.org_ _> <mailto:barry at python.org>> wrote: >> >> index() is a bit trickier because it is not tied directly to >> type conversion. In this case, int subclasses could be valid, and >> as Hrvoje later points out, returning int-subclasses from >> index() should still work for all valid use cases. > > Implementing index just means "This type can be converted to a > Python integer without losing information". Aside from that extra > "without information loss" qualification, it's the same as int.

How is that possible? Whether int or int subclass, if I'm implementing index it means my type is not an int subclass, and when I return an int I most certainly have lost information from the original type.

Without losing information about the numeric value.

Regards

Antoine.



More information about the Python-Dev mailing list