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

Ethan Furman ethan at stoneleaf.us
Tue Oct 15 18:45:59 CEST 2013


On 10/15/2013 09:28 AM, PJ Eby wrote:

On Tue, Oct 15, 2013 at 11:52 AM, R. David Murray wrote:

What about making the context manager provide the trapped exception, in a fashion similar to what assertRaises does? Sadly, that won't work, since context managers provide a value before the block is executed, not after.

However, if the CM provides the value before, and the with block accepts it, it can then have the exception added to it:

 with trap(OSError) as cm:
     os.unlink('missing.txt')
 if cm.exc:
     do_something()

-- Ethan



More information about the Python-Dev mailing list