mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
GH-73991: Make pathlib.Path.delete()
private. (#123315)
Per feedback from Paul Moore on GH-123158, it's better to defer making `Path.delete()` public than ship it with under-designed error handling capabilities. We leave a remnant `_delete()` method, which is used by `move()`. Any functionality not needed by `move()` is deleted.
This commit is contained in:
parent
a1ddaaef58
commit
033d537cd4
7 changed files with 48 additions and 287 deletions
|
@ -824,34 +824,7 @@ class Path(PathBase, PurePath):
|
|||
"""
|
||||
os.rmdir(self)
|
||||
|
||||
def delete(self, ignore_errors=False, on_error=None):
|
||||
"""
|
||||
Delete this file or directory (including all sub-directories).
|
||||
|
||||
If *ignore_errors* is true, exceptions raised from scanning the
|
||||
filesystem and removing files and directories are ignored. Otherwise,
|
||||
if *on_error* is set, it will be called to handle the error. If
|
||||
neither *ignore_errors* nor *on_error* are set, exceptions are
|
||||
propagated to the caller.
|
||||
"""
|
||||
if self.is_dir(follow_symlinks=False):
|
||||
onexc = None
|
||||
if on_error:
|
||||
def onexc(func, filename, err):
|
||||
err.filename = filename
|
||||
on_error(err)
|
||||
shutil.rmtree(str(self), ignore_errors, onexc=onexc)
|
||||
else:
|
||||
try:
|
||||
self.unlink()
|
||||
except OSError as err:
|
||||
if not ignore_errors:
|
||||
if on_error:
|
||||
on_error(err)
|
||||
else:
|
||||
raise
|
||||
|
||||
delete.avoids_symlink_attacks = shutil.rmtree.avoids_symlink_attacks
|
||||
_rmtree = shutil.rmtree
|
||||
|
||||
def rename(self, target):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue