Message199995
Issue 15806 added contextlib.ignored to the standard library (later renamed to contextlib.ignore), as a simple helper that allows code like:
try:
os.remove(fname)
except FileNotFoundError:
pass
to instead be written as:
with ignore(FileNotFoundError):
os.remove('somefile.tmp')
The point has been made that "ignore" may easily be taken to mean preventing the exception being raised *at all* (since truly ignoring the exception would mean not skipping the rest of the with statement), rather than suppressing the exception in the context manager's __exit__ method.
If you look at the rest of the contextlib docs, as well as the docs for the with statement and context manager objects, they don't refer to returning True from __exit__ as ignoring the exception, but rather as *suppressing* it. Even the docs for contextlib.ignore now make use of the term "suppress".
So I think it makes sense to rename the context manager to "suppress", while keeping the same semantics:
with suppress(FileNotFoundError):
os.remove('somefile.tmp') |
|
Date |
User |
Action |
Args |
2013-10-15 11:50:54 | ncoghlan | set | recipients:
+ ncoghlan, rhettinger |
2013-10-15 11:50:54 | ncoghlan | set | messageid: <1381837854.83.0.526181978582.issue19266@psf.upfronthosting.co.za> |
2013-10-15 11:50:54 | ncoghlan | link | issue19266 messages |
2013-10-15 11:50:54 | ncoghlan | create | |
|