<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Oct 6, 2014 at 11:24 AM, Barry Warsaw <span dir="ltr"><<a href="mailto:barry@python.org" target="_blank">barry@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">On Oct 06, 2014, at 11:04 AM, Guido van Rossum wrote:<br>
<br>
>You can construct a Path from an argument that can be either a string or<br>
>another Path. Example:<br>
><br>
>>>> from pathlib import Path<br>
>>>> p = Path('/etc/passwd')<br>
>>>> q = Path(p)<br>
>>>> p == q<br>
>True<br>
>>>><br>
><br>
>So you could start refactoring stdlib code to use Path internally without<br>
>forcing the callers to use Path, but still *allow* the callers to pass a<br>
>Path. Though I'm not sure how this would work for return values without<br>
>breaking backwards compatibility -- you'd have to keep returning strings<br>
>and the callers would have to use the same mechanism to go back to using<br>
>Paths.<br>
<br>
</span>That's a very interesting perspective, and one I'd like to pursue further.<br>
<br>
I wonder if we can take a polymorphic approach similar to some bytes/str APIs,<br>
namely that if the argument is a pathlib object, a pathlib object could be<br>
returned, and if a str was passed, a str would be returned.<br>
<br>
An example is ConfigParser.read() which currently accepts only strings. I<br>
want to pass it a Path. It would be really useful if this method returned<br>
Paths when passed paths (they're used to verify which arguments were actually<br>
opened and read).<br>
<br>
There's probably a gazillion APIs that *could* be pathlib-ified, and I'm not<br>
looking to do a comprehensive expansion across the entire stdlib. But I think<br>
we could probably take a per-module approach, at least at first, to see if<br>
there are any hidden gotchas.<br></blockquote><div> </div><div>Sounds like a plan. I'd like to see how hard it is in practice to do the polymorphic return value thing. <br></div></div><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div></div>