On Tue, Jul 30, 2019 at 9:32 AM Rhodri James firstname.lastname@example.org wrote:
I've been trying to come up with something more like this:
with something_exceptionable() as f: do_something_with(f) except with SomeException as e: handle_exception_in_setup_or_teardown(e) except SomeOtherException as e: handle_exception_in_body(e)
# Because I like this syntactic sugar too
I had to read that three times before I noticed the "with" after the "except".
Perhaps PEP 463  could be resurrected on a limited basis, allowing something like this:
with something_exceptionable() as f except SomeException -> handle_setup_exception(): do_something_with(f)
and similar for the for statement. This can result in lengthy lines, but it's going to be a bit awkward no matter what, and I feel a long line is the simplest and most readable way to get past that awkwardness. Plus, line continuations are a thing, which can make it more readable.