mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
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
This commit is contained in:
parent
1a2dd82f56
commit
d9e006bcef
4 changed files with 23 additions and 3 deletions
|
@ -1635,6 +1635,11 @@ class _BasePathTest(object):
|
|||
self.assertFileNotFound(p.stat)
|
||||
self.assertFileNotFound(p.unlink)
|
||||
|
||||
def test_unlink_missing_ok(self):
|
||||
p = self.cls(BASE) / 'fileAAA'
|
||||
self.assertFileNotFound(p.unlink)
|
||||
p.unlink(missing_ok=True)
|
||||
|
||||
def test_rmdir(self):
|
||||
p = self.cls(BASE) / 'dirA'
|
||||
for q in p.iterdir():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue