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

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


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.

Paul


More information about the Python-ideas mailing list