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~
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com