[Python-ideas] Better stdlib support for Path objects

Barry Warsaw barry at python.org
Tue Oct 7 16:24:54 CEST 2014


On Oct 07, 2014, at 02:55 PM, Paul Moore wrote:

>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).

I realize there's another thing that bugs me about sprinkling str() calls all
over the place, and this relates to my other question about whether
str()-ability is "the path protocol".

The problem is that if I'm looking at some random code and see:

    my_parser.load(str(path))

I really don't have any idea what 'path' is.  Maybe that's a good thing, but
in the few cases where I did this, it seemed bad. ;)

OTOH, if I saw this, it would be a strong clue that path were a pathlib
object:

    my_parser.load(path.string_path)

substituting .string_path for whatever color the shed gets painted.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141007/bfe9920d/attachment.sig>


More information about the Python-ideas mailing list