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

Brett Cannon brett at python.org
Thu Apr 7 13:40:23 EDT 2016

On Thu, 7 Apr 2016 at 10:19 Paul Moore <p.f.moore at gmail.com> wrote:

> On 7 April 2016 at 17:44, Chris Angelico <rosuav at gmail.com> wrote:
> > On Fri, Apr 8, 2016 at 2:11 AM, Paul Moore <p.f.moore at gmail.com> wrote:
> >> Even worse, what should open() do? It takes a string as an argument.
> >> To support patthlib, it needs to also call __fspath__. I presume you'd
> >> also want it to call __fromstring__ so that your Ascii class could be
> >> used as an argument to open as well. This is starting to seem
> >> incredibly messy to solve a problem that's basically about extending
> >> support for Python 2, which is explicitly not something the Python 3
> >> core should be doing...
> >
> > This would replace __fspath__. There'd be no need for a Path-specific
> > dunder if there's a generic "this can be treated as a string" dunder.
> So the only things that should implement the new protocol would be
> paths. Otherwise, they could be passed to things that expect a path.
> Once again, I'm confused.
> Can someone please explain to me how to decide whether my type should
> provide the new protocol. And whether my code should check the new
> protocol. At the moment, I can't answer those questions with the
> information given in this thread.

I've reached the same conclusion/point myself. The attempt to come up with
a pure solution is wreaking havoc with the practicality side of my brain
that doesn't understand the rules it's supposed to follow in order to make
this work.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160407/7562c50d/attachment.html>

More information about the Python-ideas mailing list