On Mar 31, 2020, at 03:06, Jimmy Thrasibule <[email protected]> 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. _______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/C5ATRBHHKOIOFIWET2J7ONGOJGK7VGBA/ Code of Conduct: http://python.org/psf/codeofconduct/
