homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients ncoghlan, rhettinger
Date 2013年10月15日.11:50:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1381837854.83.0.526181978582.issue19266@psf.upfronthosting.co.za>
In-reply-to
Content
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')
History
Date User Action Args
2013年10月15日 11:50:54ncoghlansetrecipients: + ncoghlan, rhettinger
2013年10月15日 11:50:54ncoghlansetmessageid: <1381837854.83.0.526181978582.issue19266@psf.upfronthosting.co.za>
2013年10月15日 11:50:54ncoghlanlinkissue19266 messages
2013年10月15日 11:50:54ncoghlancreate

AltStyle によって変換されたページ (->オリジナル) /