[Python-ideas] Better stdlib support for Path objects

Paul Moore p.f.moore at gmail.com
Tue Oct 7 15:55:58 CEST 2014


On 6 October 2014 18:47, Barry Warsaw <barry at python.org> wrote:
> I've tried to convert parts of
> a medium sized Python 3 application from os.path to pathlib and found this
> lack of support rather demotivating.  Yes, it's fairly easy to wrap Path
> objects in str() to pass them to stdlib methods that expect only strings, but
> it's a lot of work in user code and I find that the resulting str()s are
> distracting.  It's a disincentive.

I find it worse than a disincentive, it makes understanding the code
perceptibly harder, which is a maintenance issue. Having an attribute
that returns the string representation would be a substantial
improvement (as it's the extra parentheses from the str call that I
find the most distracting, that and the code smell that an "explicit
cast" involves).

Having more things accept Path objects would be good, but there will
always be 3rd party libraries, as well as places where you want to
pass a pathname that really *shouldn't* have to expect them.

Paul


More information about the Python-ideas mailing list