[issue17576] PyNumber_Index() is not int-subclass friendly (or operator.index() docos lie)

Barry A. Warsaw report at bugs.python.org
Fri Mar 29 23:29:38 CET 2013


Barry A. Warsaw added the comment:

You also end up with this nice bit of inconsistency:

>>> x = myint(7)
>>> from operator import index
>>> range(10)[6:x]
range(6, 7)
>>> range(10)[6:x.__index__()]
range(6, 8)
>>> range(10)[6:index(x)]
range(6, 7)
>>> 

Granted, it's insane to have __index__() return a different value like this, but in my specific use case, it's the type of object returned from operator.index() that's the problem.  operator.index() returns the subclass instance while obj.__index__() returns the int.

(The use case is the IntEnum of PEP 435.)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17576>
_______________________________________


More information about the Python-bugs-list mailing list