Sorry - personally I think this is absolutely ugly :-)  So I will bikeshed.

If this thread even go ahead - since the idea is not that bad, maybe allowing `try` on the same line?
Then it would be inline with `elif` - but still structured "English like" 

except ValueError try:
except TypeError:

I had sometimes needed 2 and maybe up to 3 levels of this, nothing 'blocker', but maybe,
just maybe, it would not be bad. 
However, in real life, usually one wants to put more
statements on the `except` clause than a bare nested try block. (logging, etc...)

On Tue, 15 Jun 2021 at 21:58, Chris Angelico <> wrote:
On Wed, Jun 16, 2021 at 10:51 AM Soni L. <> wrote:
> Sometimes it would be useful to be able to write:
> def foo():
>   try: return thing()
>   except ValueError;
>   try: return otherthing()
>   except ValueError;
>   try: return yetotherthing()
>   except ValueError;
>   if shouldraise(): raise
> But currently this needs to be written like so:
> def foo():
>   try: return thing()
>   except ValueError:
>     try: return otherthing()
>     except ValueError:
>       try: return yetotherthing()
>       except ValueError:
>         if shouldraise(): raise
> Look at all that unnecessary indentation! Would be nice to get rid of it.

Dangerous idea - my first interpretation of that syntax was that it
would be equivalent to "except ValueError: pass", which would be very
confusing (it's subtly different in your example with return, and
drastically different in other cases).

Are you doing this sort of thing a lot? And if you are, do you
actually need/want the exception chaining that comes from burying more
and more code into the except clauses? I know this is just a trivial
example, but I'd be looking to see if it can be done with a loop

def foo():
    for func in (thing, otherthing, yetotherthing):
        try: return func()
        except ValueError: pass

or something like that.

Python-ideas mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct: