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.
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
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
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
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