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

Brett Cannon brett at python.org
Tue Apr 12 13:33:38 EDT 2016


On Tue, 12 Apr 2016 at 10:18 Nikolaus Rath <Nikolaus at rath.org> wrote:

> On Apr 11 2016, Ethan Furman <
> ethan-gcWI5d7PMXnvaiG9KC9N7Q at public.gmane.org> wrote:
> >> As far as I can see, implementing a protocol instead of adding a few
> >> isinstance checks is more likely to make the life of a CPython developer
> >> harder than easier.
> >
> > I disagree.  And the protocol idea was not mine, so apparently other
> > core-devs also disagree (or think it's worth it, regardless).
>
> I haven't found any email explaining why a protocol would make things
> easier than the isinstance() approach (and I read most of the threads
> both here and on -dev), so I was assuming that the core-devs in question
> don't disagree but haven't considered the second approach.
>

I disagree with the idea. :) Type checking tends to be too strict as it
prevents duck typing. And locking ourselves to only what's in the stdlib is
way too restrictive when there are alternative path libraries out there
already. Plus it's short-sighted to assume no one will ever come up with a
better path library, and so tying us down to only pathlib.PurePath
explicitly would be a mistake long-term when specifying a single method
keeps things flexible (this is the same reason __index__() exists and we
simply don't say indexing has to be with a subclass of int or something).

-Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160412/723a641e/attachment.html>


More information about the Python-ideas mailing list