[Python-ideas] PEP 428 - object-oriented filesystem paths

Antoine Pitrou solipsis at pitrou.net
Sat Oct 13 19:04:21 CEST 2012

On Sun, 14 Oct 2012 02:52:18 +1000
Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Sun, Oct 14, 2012 at 2:28 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> >> You can add as many new flavours as you want, and it's only one class
> >> per flavour rather than up to 3 (the flavour itself, the pure variant
> >> and the concrete variant).
> >
> > Yes, you can. That doesn't preclude offering separate classes by
> > default, though :-)
> Factory functions would make more sense to me than separate classes -
> they're not really a different type, they're the same type using a
> different strategy for the OS dependent bits.

I find them less helpful. isinstance() calls won't work. Deriving
won't work. It makes things a bit more opaque. However, we are
definitely talking about a secondary style issue.

(note how the threading module moved away from factory functions to
regular classes :-))

> >> This class hierarchy is also more amenable to the introduction of
> >> MutablePath as a second subclass of PurePath - a path variant with
> >> mutable properties still sounds potentially attractive to me (over a
> >> wide variety of return-a-modified-copy methods for various cases).
> >
> > I'm very cold on offering both mutable on non-mutable paths. That's just
> > complicated and confusing. Since an immutable type is very desireable
> > for use in associative containers, I think immutability is the right
> > choice.
> Sure, if we're only offering one of them, then immutable is definitely
> the right choice. However, I think this is analogous to the bytes vs
> bytearray distinction - while bytes objects are more useful in
> general, using the mutable bytearray when appropriate is vastly
> superior to slicing and copying bytes objects.

bytearray was only added after a lot of experience with the 2.x str
type. I don't think we should add a mutable path API before significant
experience has been gathered about the cost and performance-criticality
of path manipulation operations. Offering both mutable and immutable
types makes learning the API harder for beginners ("which type should
I use? what happens when I combine them?").



Software development and contracting: http://pro.pitrou.net

More information about the Python-ideas mailing list