New submission from Nick Coghlan:
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')
----------
components: Library (Lib)
messages: 199995
nosy: ncoghlan, rhettinger
priority: normal
severity: normal
stage: needs patch
status: open
title: Rename contextlib.ignore to contextlib.suppress
type: enhancement
versions: Python 3.4
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19266>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com