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

Brett Cannon brett at python.org
Thu Apr 7 17:26:52 EDT 2016


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

> On 7 April 2016 at 21:28, Ethan Furman <ethan at stoneleaf.us> wrote:
> > In case there's any confusion: by "not work" I mean the stdlib is not
> going
> > to correctly interpret a pathlib.Path in 3.3 and earlier.
>
> I think the confusion is over *who* will be checking the protocol or
> the ABC. You're correct that the stdlib will not do so in earlier
> versions. I've been assuming that is obvious (and I suspect Brett has
> too).


Yep, you're right. I was never worried about making the stdlib work since
that's a fully controlled environment that we can update at once. What I'm
worried about is any third-party library that has an API that takes a path
as an argument that may need to be updated to support pathlib -- or any
other path library -- and doesn't want to directly rely on Python 3.6 for
support.


> Talk about using the check for older versions is basically
> around the possibility that 3rd party libraries might do so. I think
> it's unlikely that they'll bother (but I'm commenting on the
> suggestion because I'd like it to be easy to do if anyone does want to
> bother, against my expectations). I have the feeling Brett might think
> that it's somewhat more likely.
>

Yes, that's my hope as third-party libraries are the ones that have older
Python version compatibility to care about (the stdlib is obviously always
latest-and-greatest).


>
> If all we're thinking about is a way for the stdlib to work with
> strings and pathlib objects seamlessly, while also allowing 3rd party
> path classes to register to be treated the same way, then yes, there's
> no real difference between an ABC and a protocol (well, to register
> with the ABC, 3rd party code would need to conditionally import the
> ABC and make sure not to fail if the ABC can't be found, but that's
> just some boilerplate).
>

My point is the boilerplate is minimized for third-party libraries in the
instance of the magic method vs the ABC, but otherwise they accomplish the
same thing.


>
> Frankly, if it wasn't for the fact that you have stated that you'll
> add support for the protocol to your path library, I'd be surprised if
> *any* 3rd party code changed as a result of this discussion. There's
> been no comment from the authors of path.py or pylib (the only other 2
> path objects I know of). And the only comments I've heard from authors
> of libraries that consume paths is "I don't see any reason why I'd
> bother". So as long as you're happy with the final form of the
> proposal, I see little reason to worry about how other 3rd party code
> might use it.
>

I'm trying to be a bit more optimistic on the uptake. :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160407/68978526/attachment-0001.html>


More information about the Python-ideas mailing list