-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Callable supplied to shutil.rmtree(onexc=...)
should accept a single argument
#103218
Comments
The
To be strictly correct, we could eliminate the try:
if os.path.islink(path):
# symlinks to directories are forbidden, see bug #1669
raise OSError("Cannot call rmtree on a symbolic link")
except OSError as err:
onexc(os.path.islink, path, err)
# can't continue even if onexc hook returns
return
try:
if os.path.isjunction(path):
raise OSError("Cannot call rmtree on a junction")
except OSError as err:
onexc(os.path.isjunction, path, err)
return In either case, a good way to resolve the error is to delete the symlink or junction reparse point. The upside of calling the error handler with
Note that the existing |
When is the exception (and file path) not enough to determine that?
That kind of illustrates why I dislike this: it makes the internal implementation part of the function's public interface. We have an opportunity to remove this feature while we're adjusting the error handling in |
Granted, but I wouldn't hold up Possibly the strongest argument in favor of doing away with the |
3.12 beta 1 is out, so there's no longer an opportunity to revise the argument. Closing this ticket! |
The
onexc
argument was added two weeks ago to replaceonerror
: d51a6dcThough it improves the third argument (replacing a 3-tuple with the exception object), I think we should also consider two further improvements while we're in the business of replacing
onerror
, as the opportunity may not come again for a long time:function
, provides an unreasonably deep insight into the internals ofrmtree()
. The implementation already bends the truth, for example supplyingos.path.islink
when a junction check fails. Error reporting can already be achieved by printing or re-raising the exception. It's not used in the standard library (e.g. bytempfile
). What legitimate use cases are there? I propose we remove it!path
, is already be available viaexc.filename
. This is noted inos.walk()
's documentation of itsonerror
argument. Also propose we remove it.If we make
onexc
accept a single argument, it would align with theonerror
argument toos.walk()
andos.fwalk()
, and provide more relevant (/less redundant) information.The text was updated successfully, but these errors were encountered: