Suggested python feature: allowing except in context maneger

Cameron Simpson cs at cskk.id.au
Fri Jun 14 22:56:35 EDT 2024


On 14Jun2024 09:07, Yair Eshel <guruyaya at gmail.com> wrote:
>Cameron, I'm not really sure I got your point. I've used the "file not
>found" exception as an example for a behavior typical on context managers.
>This could be a failure to connect to DB, or threads. It also applies to
>any kind of possible exception, whether cased by the context manager itself
>or the lines inside it. Long story short, this syntax change is as useful
>as context managers are

The example exception is not what bothers me. The syntax change is 
nowhere near as useful as `with` and context managers. They provide an 
excellent idiom for resource usage and release.

Your suggestion complicates the `with` statement and brings only a tiny 
indentation reduction over the `with`-inside-`try` idiom. It brings no 
semantic changes or new features.

That is why I'm -1: the benefit is triviailly small to my eye.


More information about the Python-list mailing list