Sujet : Re: Suggested python feature: allowing except in context maneger
De : cs (at) *nospam* cskk.id.au (Cameron Simpson)
Groupes : comp.lang.pythonDate : 15. Jun 2024, 03:56:35
Autres entêtes
Message-ID : <mailman.140.1718420202.2909.python-list@python.org>
References : 1 2
User-Agent : Mutt/2.2.13 (2024-03-09)
On 14Jun2024 09:07, Yair Eshel <
guruyaya@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.