Ethan Furman added the comment:

Victor Stinner commented:
-------------------------
> I never understood the difference between "long" (__int__ method)
> and "index" (__index__ method). Is the difference on the behaviour
> of floating point numbers?

__index__ was originally added so that non-int integers, such as NumPy's int16, 
int32, etc, integer types could be used as indices and slices.

Now it means "if your type can produce a lossless integer, use __index__", 
which is why float and similar types don't define it.

The current meaning is unfortunate in that it is possible to want a type that 
can be used as an index or slice but that is still not a number, and in fact 
won't be used as a number in any scenario _except_ bin(), hex(), and oct().

It seems to me that by having those three functions check that the argument is 
a number, and bailing if it is not, is a decent way to ensure consistency.

One question I do have, since I don't have NumPy installed, is what happens 
with:

  --> "NumPy's int's work here? %x" % uint16(7)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue19995>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to