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

Brett Cannon report at bugs.python.org
Sun Nov 22 21:06:51 EST 2020


Brett Cannon <brett at python.org> added the comment:

I think operator.index() should be brought to be inline with PyNumber_Index():

- If the argument is a subclass of int then return it.
- Otherwise call type(obj).__index__(obj)
- If not an int, raise TypeError
- If not a direct int, raise a DeprecationWarning

The language reference for __index__() suggests this is the direction to go (https://docs.python.org/3/reference/datamodel.html#object.__index__).

----------
nosy: +brett.cannon

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


More information about the Python-bugs-list mailing list