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

Paul Moore p.f.moore at gmail.com
Thu Apr 7 09:41:18 EDT 2016


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.

For that matter, what constitutes a "lossless conversion to str"? If
you mean "doesn't lose information", then integers could easily be
said to have such a conversion - but that doesn't seem right (we don't
want things to start auto-converting numbers to strings).

I'm not sure I understand the point.

Paul


More information about the Python-ideas mailing list