gh-52769: Return list of errors in shutil.rmtree when ignore_errors=True#108255
gh-52769: Return list of errors in shutil.rmtree when ignore_errors=True#108255richardhob wants to merge 14 commits intopython:mainfrom
Conversation
Update `test_rmtree_errors_onexc` to use the provided `errors` return value from `shutil.rmtree` when ignoring errors (`ignore_errors=True`).
This errors list will contain the platform / implementation dependant details in which the error occurred ((func, path, exc) from `onexc`).
When shutil.rmtree is provided with *ignore_errors=True* then the function will return a list of errors as [(function, path, excinfo), ...].
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
How I see it is that the
The argument is that the I would argue that: >>> errors = shutil.rmtree(path, ignore_errors=True)Makes more sense than: >>> errors = []
>>> def my_onexc(*args):
... errors.append(args)
>>> shutil.rmtree(path, onexc=my_onexc)But this has been the way that I have made the requested changes; please review again |
|
Thanks for making the requested changes! @hauntsaninja: please review the changes made to this pull request. |
|
I concur with @hauntsaninja. It is easy to do with the existing error handler argument. When you try to remove a large read-only three with |
Resolve #52769
This merge request adds an
errorsreturn value to theshutil.rmtree, based on the patch written in the #pycon 2013 sprint by andrewg (with r.david.murray's assistance). I have attempted to add documentation to explain the purpose of theerrorsreturn value as well.Example 1: Path that does not exist
Example 2: Read Only folder with a Read Only File
The discussion in this issue revolves around the complexity of the
onerrorfunction, and what the purpose of theonerror(nowonexc) function is.The conclusion from what I read:
shutil.rmtreeshould not try to delegate the hard work [of removing files and folders, dealing with permissions, etc.] to third party codeshutil.rmtreeshould return failures / errors, similar to howsmtpreturns a list of mails that could not be sentAddittional features mentioned that are not implemented but are mentioned:
shutil.rmtreecould check to make sure the permissions are the same throught the treeshutil.rmtreecould check and see if there are any links what will make the function fail📚 Documentation preview 📚: https://cpython-previews--108255.org.readthedocs.build/