diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-08-26 15:26:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-26 15:26:34 (GMT) |
commit | 033d537cd4b8c12f2441f1c23960c2153122140a (patch) | |
tree | 7817074e7c0cb80970d70cf68e1d87f99ab6b57a /Doc | |
parent | a1ddaaef58e21551399ee3d30d592cd336baec4c (diff) | |
download | cpython-033d537cd4b8c12f2441f1c23960c2153122140a.zip cpython-033d537cd4b8c12f2441f1c23960c2153122140a.tar.gz cpython-033d537cd4b8c12f2441f1c23960c2153122140a.tar.bz2 |
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.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/pathlib.rst | 39 | ||||
-rw-r--r-- | Doc/whatsnew/3.14.rst | 5 |
2 files changed, 4 insertions, 40 deletions
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 0b6a6a3..4a8de26 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -1657,7 +1657,7 @@ Copying, moving and deleting .. method:: Path.unlink(missing_ok=False) Remove this file or symbolic link. If the path points to a directory, - use :func:`Path.rmdir` or :func:`Path.delete` instead. + use :func:`Path.rmdir` instead. If *missing_ok* is false (the default), :exc:`FileNotFoundError` is raised if the path does not exist. @@ -1671,42 +1671,7 @@ Copying, moving and deleting .. method:: Path.rmdir() - Remove this directory. The directory must be empty; use - :meth:`Path.delete` to remove a non-empty directory. - - -.. method:: Path.delete(ignore_errors=False, on_error=None) - - Delete this file or directory. If this path refers to a non-empty - directory, its files and sub-directories are deleted recursively. - - If *ignore_errors* is true, errors resulting from failed deletions will be - ignored. If *ignore_errors* is false or omitted, and a callable is given as - the optional *on_error* argument, it will be called with one argument of - type :exc:`OSError` each time an exception is raised. The callable can - handle the error to continue the deletion process or re-raise it to stop. - Note that the filename is available as the :attr:`~OSError.filename` - attribute of the exception object. If neither *ignore_errors* nor - *on_error* are supplied, exceptions are propagated to the caller. - - .. note:: - - When deleting non-empty directories on platforms that lack the necessary - file descriptor-based functions, the :meth:`~Path.delete` implementation - is susceptible to a symlink attack: given proper timing and - circumstances, attackers can manipulate symlinks on the filesystem to - delete files they would not be able to access otherwise. Applications - can use the :data:`~Path.delete.avoids_symlink_attacks` method attribute - to determine whether the implementation is immune to this attack. - - .. attribute:: delete.avoids_symlink_attacks - - Indicates whether the current platform and implementation provides a - symlink attack resistant version of :meth:`~Path.delete`. Currently - this is only true for platforms supporting fd-based directory access - functions. - - .. versionadded:: 3.14 + Remove this directory. The directory must be empty. Permissions and ownership diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 34434e4..ee7d333 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -185,14 +185,13 @@ os pathlib ------- -* Add methods to :class:`pathlib.Path` to recursively copy, move, or remove - files and directories: +* Add methods to :class:`pathlib.Path` to recursively copy or move files and + directories: * :meth:`~pathlib.Path.copy` copies a file or directory tree to a destination. * :meth:`~pathlib.Path.copy_into` copies *into* a destination directory. * :meth:`~pathlib.Path.move` moves a file or directory tree to a destination. * :meth:`~pathlib.Path.move_into` moves *into* a destination directory. - * :meth:`~pathlib.Path.delete` removes a file or directory tree. (Contributed by Barney Gale in :gh:`73991`.) |