[Python-ideas] Potential PEP: with/except

David Mertz mertz at gnosis.cx
Tue Jan 22 16:26:39 EST 2019


You could write a context manager that used an arbitrary callback passed in
to handle exceptions (including re-raising as needed). This doesn't require
new syntax, just writing a custom CM.

On Tue, Jan 22, 2019, 4:20 PM Barry Scott <barry at barrys-emacs.org wrote:

>
>
> On 22 Jan 2019, at 20:31, Michael Selik <mike at selik.org> wrote:
>
> On Tue, Jan 22, 2019, 12:11 PM Paul Ferrell <pflarr at gmail.com wrote:
>
>> I see this as the natural evolution of what 'with' is all about -
>> replacing necessary try-finally blocks with something more elegant. We just
>> didn't include the 'except' portion.
>>
>
> The time machine strikes again. In fact, you can handle exceptions with a
> context manager object. Whatever you're with-ing must have a dunder exit
> method, which received any exceptions raised in the block as an argument.
> Return true and the exception is suppressed.
>
>
> Suppressing the exception is not the general case.
> And will not work for the example given.
>
> Barry
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190122/54fdce72/attachment.html>


More information about the Python-ideas mailing list