[Python-ideas] Object interface to path names

Nick Coghlan ncoghlan at gmail.com
Wed Sep 14 00:49:01 CEST 2011

On Wed, Sep 14, 2011 at 1:33 AM, David Townshend <aquavitae69 at gmail.com> wrote:
>> Having an object-oriented / polymorphic file API means that one can
>> provide file objects that aren't backed by the filesystem, but look
>> the same. This is cool in that you can do things like treat zip files
>> as directory, or mock out the filesystem for a unit test, without
>> worrying about monkeypatching builtins or using a nonstandard wrapper
>> API etc.
> Great use case!  And using factories to create create the objects would make
> this especially powerful.

The thing is, the "smart path" abstraction level isn't adequate for
that task - you need to do more to ensure various primitives (like
listing directory contents) are handled properly, along the lines of
what PyFileSystem provides (https://code.google.com/p/pyfilesystem/).

As far as a smart path object goes, the previous major effort on this
front was PEP 355, which focused on the API offered by Jason
Orendorff's path module. While the PEP was ultimately rejected due to
the "one class to rule them all" nature of that particular interface,
it's still an excellent reference on why improving the standard
library's filesystem abstraction is an area worth exploring further.

FWIW, PyFileSystem is the only package I've seen that I think comes
close to getting the abstraction level right (I've never actually
needed to use it for anything though).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list