Walter Dörwald wrote:
M.-A. Lemburg wrote:
So the question is whether conversion of a Unicode sub-type to a true Unicode object should honor __unicode__ or not.
The same question can be asked for many other types, e.g. floats (and __float__), integers (and __int__), etc.
... def __float__(self): ... return 3.141 ...
... def __int__(self): ... return 42 ...
I think we need general consensus on what the strategy should be: honor these special hooks in conversions to base types or not ?
I'd say, these hooks should be honored, because it gives us more possibilities: If you want the original value, simply don't implement the hook.
Maybe the string case is the real problem ... :-)
At least it seems that the string case is the exception.
So if we fix __str__ this would be a bugfix for 2.4.1. If we fix the rest, this would be a new feature for 2.5.
I have a feeling that we're better off with the bug fix than the new feature.
__str__ and __unicode__ as well as the other hooks were specifically added for the type constructors to use. However, these were added at a time where sub-classing of types was not possible, so it's time now to reconsider whether this functionality should be extended to sub-classes as well.