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

2021-08-31 Thread STINNER Victor
STINNER Victor added the comment: > If we go in this direction we should add a DeprecationWarning for __str__() > returning not direct str. I saw str subclass being used for translation. Example: class Message(str): """A Message object is a unicode object that can be translated.

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

2021-08-31 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: PyNumber_Index() now always returns an instance of int. - If the argument is a direct int then return it. - If it is a subclass of int then return a direct int copy. - Otherwise call type(obj).__index__(obj) - If a direct int, return it - If a subclass of

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

2021-08-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: > So I really *do* want to see the ability of __float__ > to return a non-float eventually removed. Note, the __str__ method on strings does not require an exact str. class S: def __str__(self): return self

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

2020-11-22 Thread Brett Cannon
Brett Cannon 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

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

2020-11-22 Thread Brett Cannon
Change by Brett Cannon : -- title: PyNumber_Index() is not int-subclass friendly (or operator.index() docos lie) -> PyNumber_Index() is not int-subclass friendly (or operator.index() docs lie) ___ Python tracker