diff options
author | ‮zlohhcuB treboR <robert.buchholz@goodpoint.de> | 2019-05-15 22:02:11 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-05-15 22:02:11 (GMT) |
commit | d9e006bcefe6fac859b1b5d741725b9a91991044 (patch) | |
tree | 47d9d85984d3767ae0a24e58b33e4a75e65e3372 /Doc | |
parent | 1a2dd82f56bd813aacc570e172cefe55a8a41504 (diff) | |
download | cpython-d9e006bcefe6fac859b1b5d741725b9a91991044.zip cpython-d9e006bcefe6fac859b1b5d741725b9a91991044.tar.gz cpython-d9e006bcefe6fac859b1b5d741725b9a91991044.tar.bz2 |
bpo-33123: pathlib: Add missing_ok parameter to Path.unlink (GH-6191)
Similarly to how several pathlib file creation functions have an "exists_ok" parameter, we should introduce "missing_ok" that makes removal functions not raise an exception when a file or directory is already absent. IMHO, this should cover Path.unlink and Path.rmdir. Note, Path.resolve() has a "strict" parameter since 3.6 that does the same thing. Naming this of this new parameter tries to be consistent with the "exists_ok" parameter as that is more explicit about what it does (as opposed to "strict").
https://bugs.python.org/issue33123
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/pathlib.rst | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 41aebc4..166de8d 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -1048,11 +1048,20 @@ call fails (for example because the path doesn't exist). otherwise :exc:`FileExistsError` is raised. -.. method:: Path.unlink() +.. method:: Path.unlink(missing_ok=False) Remove this file or symbolic link. If the path points to a directory, use :func:`Path.rmdir` instead. + If *missing_ok* is false (the default), :exc:`FileNotFoundError` is + raised if the path does not exist. + + If *missing_ok* is true, :exc:`FileNotFoundError` exceptions will be + ignored (same behavior as the POSIX ``rm -f`` command). + + .. versionchanged:: 3.8 + The *missing_ok* parameter was added. + .. method:: Path.link_to(target) |