[Python-ideas] String interpolation again.
masklinn at masklinn.net
Fri Jul 23 16:14:59 CEST 2010
On 2010-07-23, at 16:09 , Mike Meyer wrote:
>>> In python, that would be making
>>> str.__add__ (and friends) do the conversion.
>> You'd run into the issues of writing `a + "foo"` with `a` defining a custom `__add__`, which would not perform string concatenation, as per Python's operator resolution order.
> That's what the "and friends" is for. str.__radd__ is one of the
> friends. If the type of a refused to do the add, then str.__radd__
> would get it, and could do the conversion and concatenation.
> Of course, if the type of a did the add in some way *other* than via
> the conversion and concatenation, then that's what would happen. Which
> is one of the reasons this type of implicit conversion isn't right for
Right. Because otherwise it should not be very hard (which doesn't mean it would be smart) to remove the type error from str.__add__ and str.__radd__ and just str() the argument if it isn't already a string.
More information about the Python-ideas