[issue33498] pathlib.Path wants an rmtree method

Aaron Hall report at bugs.python.org
Tue May 15 12:08:09 EDT 2018


Aaron Hall <aaronchall at yahoo.com> added the comment:

> What is wrong with just using shutil.rmtree()?

0. It's awkward to import just for demonstrations.
1. It's harder for new pythonists to discover.
2. A method provides discoverability in an object's namespace.
3. rmtree is a method of paths (typical usage is rmtree(path)).
4. rmtree is clearly functionality that is missing from the Path object (which has effectively rm, rm -d, but not rm -r).

> You can't deal with files with only using pathlib. You can't read ZIP archives, open temporary files, import modules, download files from Internet and open them in the webbrowser, run subprocesses, send files by e-mail, determine the MIME type of files, read WAV files with only using pathlib.

I wasn't suggesting those things. After some thought, I would probably not support those things to be in pathlib either. Maybe they are "file" methods, but to me, they are not semantically "path" methods. That functionality is in much more specialized domain-oriented modules, and easy to discover. 

We need a recursive rmdir so that users aren't tempted to roll their own - and wind up deleting symlinked things.

I *would* support some of those other shutil functions to become Path methods, perhaps move, copy2, and copytree, as they *are* path methods (you just need to supply another destination path), but I'm not finding it to be a pain point yet.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33498>
_______________________________________


More information about the Python-bugs-list mailing list