Hmm, ok, I can work with that :)

If I were writing Python right now, I would argue that if you're going to
build this try/except/else/finally construct, each of the three result
clauses represent potential outcomes. The fail case, the success case, and
the no-matter-what case. And then, you should be consistent about what
happens when any of the three are omitted. If `except` is omitted, then
catch the generic exception and do nothing and exit. If `else` is omitted,
do nothing and exit. And finally, if `finally` is omitted, (surprise!) do
nothing and exit. Then, with this as a guiding principle, a user can choose
to omit any or all of those actions that they desire, except where it is
unreasonable to omit that combination. `try` by itself just silently
catches errors and does nothing, and so it seems justifiably invalid as an
abuse of the construct. Same principle actually applies to `try/else` in my
mind, since it is functionally no different. But the `try/else/finally`
statement actually has meaning: try something, do something if it succeeds,
and then do something else regardless of what happens. I don't see an
obvious reason why it doesn't exist (except perhaps the notion that an else
without an except is just semantically odd), and in fact it comes to me as
something of a surprise that it's disallowed.

All said, I'm obviously not writing Python today—and I also don't maintain
it—so I fully appreciate my own dreams of logical consistency above all
else are unlikely to be an opinion shared among the developers. I do
appreciate that this language is not changing nonstop beneath my feet, so
the inertia is frustratingly welcome.

-Mitch

On Tue, Aug 1, 2023 at 3:06 PM Chris Angelico <ros...@gmail.com> wrote:

> On Wed, 2 Aug 2023 at 04:03, Mitch <mitchell.negus...@gmail.com> wrote:
> > I'll ask the same question as OP: "Is there a reason why else without
> except has to be invalid syntax?"
> >
>
> A better question is: "Is there a reason why else without except
> should be valid syntax?"
>
> ChrisA
> _______________________________________________
> 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/BMYQ2U5EX7XH46DAUQTGC373TSU5IGVC/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
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/SLNROGWWZ4YHYL4QI6JUGFKMIERMVKE2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to