[Python-Dev] cpython: Rename contextlib.ignored() to contextlib.ignore().

Ethan Furman ethan at stoneleaf.us
Sun Oct 13 16:20:08 CEST 2013


On 10/13/2013 05:34 AM, Antoine Pitrou wrote:
> On Sun, 13 Oct 2013 16:57:09 +1000
> Nick Coghlan <ncoghlan at gmail.com> wrote:
>>
>> For the record, this thread did prompt me to consider the new construct
>> anew, but on reflection, I still consider it a reasonable addition to
>> contextlib.
>>
>> It substantially improves the simple cases it is intended to help with,
>> and, if anything, makes overly broad exception suppression *more* obviously
>> dubious (because the name of the construct doesn't match the consequences
>> for multi-line suites).
>
> Why? Anyone can still write "try ... except".

True, but Raymond's example of

     with ignore(OSError):
         os.remove('somefile')

struck a chord -- I've used the try ... except version of that many times, and each time it's been a pain.  I now agree 
this context manager is a win.

--
~Ethan~


More information about the Python-Dev mailing list