[Python-ideas] Pathlib additions & changes

Paul Moore p.f.moore at gmail.com
Mon Jun 22 17:59:26 CEST 2015


On 22 June 2015 at 15:59, Chris Angelico <rosuav at gmail.com> wrote:
> On Mon, Jun 22, 2015 at 6:30 PM, David Townshend <aquavitae69 at gmail.com> wrote:
>> 3.  There are several other minor irritations where a common pattern
>> requires several lines or the use of a lower-level library such as shutil.
>> For example:
>>
>>   *  Recursively remove a directory (no sane way using pathlib alone)
>>     shutil.rmtree(str(path))
>
> I'm not sure shutil should be considered a lower-level library. It's a
> separate set of tools aimed at shell-like functionality. Removing a
> directory tree seems right for shutil; what if shutil.rmtree() would
> accept a Path object as an alternative to a str? That'd make
> reasonable sense, and it'd feel like the two modules were working well
> together.

Agreed, shutil is higher level than pathlib, not lower.

Having more stdlib functions (shutil is the most obvious example, but
there are others) take pathlib.Path objects as well as strings would
be a good change (and would set a nice example for 3rd party file
manipulation modules). I'm sure the usual "patches welcome" applies
:-)

The main irritation about using "higher level" modules with path
objects is the proliferation of str() calls. Accepting path objects
natively fixes that:

    from shutil import rmtree
    rmtree(path)

looks fine to me.

Paul


More information about the Python-ideas mailing list