[Python-Dev] Backward compatibility of shutil.rmtree

Hynek Schlawack hs at ox.cx
Mon May 21 00:17:40 CEST 2012

Am 20.05.12 23:46, schrieb martin at v.loewis.de:

>>>> Two of them differ in the new version: os.fwalk() is used instead of
>>>> os.listdir() and os.unlinkat() instead of os.remove().
>>> It would be os.flistdir instead of os.listdir, not os.fwalk, right?
>> It’s actually os.fwalk. It has been implemented by Charles-François as a
>> dependency of the ticket because it seemed generally useful – therefore
>> I used it for the implementation.
> I think that's a mistake then, because of the limited error reporting.
> With os.fwalk, you don't know exactly what it is that failed, but it
> may be useful to know.

Well, as fwalk does only directory traversing, it means that something
went wrong while doing so. The exception should be more helpful at this
point, no?

> So I propose to duplicate the walking in rmtree.

I'm -1 on that one; the information gain doesn’t seem that big to me and
doing fwalk right isn't trivial (see

It’s easy to do a copy’n’paste now but the trade-off of having to
maintain both for a bit more of information from a high level function
doesn’t seem worth to me.

> I also wonder how exactly in your implementation directory handles
> get closed, and how that correlates to attempts at removing the
> directories.

Directory handles get closed inside of fwalk (try/finally) – but I think
it’s easier if you take a quick look yourself before I explain things to
you you didn’t want to know. :)


More information about the Python-Dev mailing list