[Python-ideas] Dunder method to make object str-like

Paul Moore p.f.moore at gmail.com
Thu Apr 7 11:01:12 EDT 2016


On 7 April 2016 at 15:07, Random832 <random832 at fastmail.com> wrote:
> On Thu, Apr 7, 2016, at 09:41, Paul Moore wrote:
>> On 7 April 2016 at 14:04, Chris Angelico <rosuav at gmail.com> wrote:
>> > Proposal: Objects should be allowed to declare that they are
>> > "string-like" by creating a dunder method (analogously to __index__
>> > for integers) which implies a loss-less conversion to str.
>>
>> What would this be used for? Other than Path, what types would be
>> viable candidates for being "string like"? I can't think of a use case
>> for this feature.
>
> How about ASCII bytes strings? ;)

OK, I guess. I can't see why it's a significant enough use case to
justify a new protocol, though.

>> For that matter, what constitutes a "lossless conversion to str"?
>
> What's __index__ for?

I don't follow. It's for indexing, which requires an integer. How does
that relate to the question of what constitutes a lossless conversion
to str?
Paul


More information about the Python-ideas mailing list