Nick Coghlan added the comment:
(Note: I'm not yet convinced this is a good idea. I'm definitely considering
it, though)
As with many context managers, a key benefit here is in the priming effect for
readers. In this code:
try:
# Whatever
except (A, B, C):
pass
the reader doesn't know that (A, B, C) exceptions will be ignored until the
end. The with statement form makes it clear before you start reading the code
that certain exceptions won't propagate:
with ignored(A, B, C):
# Whatever
I'm not worried that it makes things less explicit - it's pretty obvious what a
context manager called "ignored" that accepts an arbitrary number of exceptions
is going to do.
One other thing it does is interact well with ExitStack - you can stick this in
the stack of exit callbacks to suppress exceptions that you don't want to
propagate.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue15806>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com