On Tue, Jul 30, 2019 at 9:32 AM Rhodri James <rho...@kynesim.co.uk> 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 [1] 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. [1] https://www.python.org/dev/peps/pep-0463/ _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CG77KVVOEQUT2MNN5STAIA3G76MFM4IZ/ Code of Conduct: http://python.org/psf/codeofconduct/