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

Koos Zevenhoven k7hoven at gmail.com
Sat Mar 26 20:33:36 EDT 2016


On Sun, Mar 27, 2016 at 1:23 AM, Koos Zevenhoven <k7hoven at gmail.com> wrote:

> On Sat, Mar 26, 2016 at 9:10 PM, Brett Cannon <brett at python.org> wrote:
>
>> [...]
>>
> I also want to mention two things. One, pathlib.path is a thing now and
>> something most people are probably not aware of as an alternative to doing
>> `str(path)`:
>> https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.path .
>>
>
> I assume you meant to type pathlib.Path.path, so that Path("...").path ==
> str(Path("...")). That's a good start, and I'm looking forward to Serhiy's
> patch for making the stdlib accept Paths. But if Path will not subclass
> str, we also need new stdlib functions that *return* Paths.
>
>
Well, just to reply to myself, here's a slightly crazy idea, which I'll
mention before I realize that it's a bad idea:

What if there was a another class, say StringPath, that inherits from both
str and Path, which wraps another instance of Path, but is also a str. When
you call its Path methods, it would delegate them to the wrapped Path
object so that functions that now return paths as plain str could in future
versions start returning that type?

 - Koos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160327/470c3ca2/attachment.html>


More information about the Python-ideas mailing list