[Python-ideas] Dunder method to make object str-like
rosuav at gmail.com
Fri Apr 8 13:42:24 EDT 2016
On Thu, Apr 7, 2016 at 11:04 PM, Chris Angelico <rosuav at gmail.com> wrote:
> This is a spin-off from the __fspath__ discussion on python-dev, in
> which a few people said that a more general approach would be better.
> 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.
> This could supersede the __fspath__ "give me the string for this path"
> protocol, or could stand in parallel with it.
In the light of all the arguments put forward in this thread and
elsewhere, I'm withdrawing this proposal in favour of __fspath__. If
additional use-cases are found for a "string-like object", this can be
revived, but otherwise, it's too general and insufficiently useful.
More information about the Python-ideas