On 04/03/2013 08:14 AM, Nick Coghlan wrote:
On 4 Apr 2013 00:18, "Barry Warsaw" <ba...@python.org
<mailto:ba...@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.
--
~Ethan~
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com