[Python-ideas] Working with Path objects: p-strings?

Paul Moore p.f.moore at gmail.com
Thu Mar 31 05:15:53 EDT 2016


On 31 March 2016 at 10:09, Sven R. Kunze <srkunze at mail.de> wrote:
> On 30.03.2016 18:49, Ethan Furman wrote:
>>
>> A solution here is to return what you receive:
>>
>> - str coming in? str going out
>> - path coming in? path going out
>>
>> Of course, this gets muddied when multiple path/str arguments are accepted
>> coming in.
>
> I have bad memories about this kind of approach. It reminds me of the
> peculiarity of os(.path)-related functions in Python 2 that return either
> bytes or unicode depending on the argument's type.
>
> That's utterly confusing and I remember us hunting bugs related to this for
> hours (basically looking for "where does this byte string come from?").

Any suggestions for a better design? It might be nice for someone to
write a blog entry or posting somewhere on "how to upgrade your 3rd
party library to support pathlib" and one of the harder questions will
be "how do I decide whether to return a string or a path?" If we had a
good recommendation for this, it might help adoption.

Paul


More information about the Python-ideas mailing list