
On Mar 31, 2020, at 03:06, Jimmy Thrasibule <jimmy.thrasibule@gmail.com> wrote:
But if you use a context manager which silences the exception, like contextlib.suppress() or unittest.TestCase.assertRaises(), it is easy to do too.
was_not_raised = False with my_context(): do_something_sensitive() was_not_raised = True if was_not_raised: print("We're all safe.")
That is indeed a way to workaround my use case. I do still find a with/else more elegant.
It might help your proposal to just show a small concrete and realistic example of how this workaround parallels the workaround for not having for/else, and how your proposed change would let you improve your code’s readability in exactly the same way as for/else. At least for me, it’s always been easier to show a newcomer to Python the point of for/else with a nice example than to try to explain the semantics and why they’re useful, and I assume the same would be true here.