[issue33123] Path.unlink should have a missing_ok parameter
Serhiy Storchaka
report at bugs.python.org
Tue Jul 17 09:10:28 EDT 2018
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
It can be written as
try:
path.inlink()
except FileNotFoundError:
pass
If you want to save few lines of code, you can use contextlib.suppress().
with suppress(FileNotFoundError): path.inlink()
I suggest to close this issue. It is better to keep the API simple and orthogonal. Adding an option in Path.unlink() will require adding this support of this option in third-part implementations of Path. In general, adding a single boolean parameter is not considered a good practice in Python.
A "strict" parameter in Path.resolve() does the different thing. In both cases Path.resolve() returns a value, and you can't implement strict=False by catching exception externally.
----------
nosy: +pitrou, serhiy.storchaka
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33123>
_______________________________________
More information about the Python-bugs-list
mailing list