Nathaniel Smith writes:
 > On Sat, Mar 17, 2018 at 10:15 AM, Stephen J. Turnbull
 > <turnbull.stephen...@u.tsukuba.ac.jp> wrote:
 > > (5) perform operations on several objects denoted by Paths at once
 > >     (copy and its multiple operand variants),
 > 
 > Sure it does: Path.rename and Path.replace.

I was very careful about the semantics.  Those are *single objects*
denoted by multiple Paths (at different times).  You could argue
multiple objects for Path.replace, but I consider maybe removing the
reference to the original target of the new Path to be an edge case
that you need to address if you have Path.rename.

 > Similarly, it's hard to explain why we have Path.mkdir but not
 > Path.makedirs

So what?  Let's fix that.  As you propose:

 > (maybe it should be Path.mkdir(include_parents=True)

is fine, although that default seems a little risky vs. typos.  I know
I have confused myself with mkdir -p that way a few (though very few)
times.  Perhaps Guido would prefer Path.makedirs for this functionality.

 > and Path.unlink(recursive=True)

I dislike that API, to be honest (at least two interpretations: rmtree
and remove_empty_directories=True).  I would definitely call the more
destructive operation Path.rmtree.

 > but there's definitely room for improvement.

I didn't deny that.  All I argued was that, no, it really seems
unlikely to me that Antoine intended pathlib to become Emacs.  And I
am against the PEP in its current form where it clearly intends to
incorporate practically everything in os (dealing with filesystem
objects) and shutil.  Those APIs are not clean.

I also feel that before we do anything but the minor filling-in
exercises discussed explicitly above, we should see if we can add
URIPath conforming to RFC 3986 and RFC 3987.  Echoing Antoine's
misgivings, I'm dubious about that, though, because Antoine
implemented the concrete "realpath" semantics (resolve links before
..) in pathlib, while RFC 3986 specifies formal path manipulation
semantics to prevent traversal above DocumentRoot and similar
exploits.  In web programming URIPath to Path conversions, and vice
versa, will be very common, but I suspect at least one direction will
be fragile because conversion and canonicalize won't commute.  I hope
I'm wrong![1]

Well we know where we're going
But we don't know where we've been
And we know what we're knowing
But we can't say what we've seen

We're on a Path to nowhere
Come on inside
Taking that ride to nowhere
We'll take that ride

:-)

Footnotes: 
[1]  Perhaps that can be fixed by recommending a single composed
operation that is safe.  Maybe the simple conversion operations
themselves can be "private" methods.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to