On Sun, May 9, 2021 at 5:08 PM Chris Angelico <rosuav@gmail.com> wrote:
On Mon, May 10, 2021 at 9:57 AM Steven D'Aprano <steve@pearwood.info> wrote:
>
> On Sun, May 09, 2021 at 04:45:55PM -0000, Thomas Grainger wrote:
>
> > now that python2.7 is EOL, it might be worth resurrecting this syntax
> [...]
> > except E1, E2, E3 as e:
>
> What advantages will this new syntax bring us?
>
> Will it allow us to do things that we can't currently do?
>
> When would you use it in preference to the existing syntax? By this I
> mean both under what circumstances, and at what time (tomorrow? in a
> year? in ten years?).
>
> Is there an aim beyond saving two characters?
>

It would remove a level of frustration. I've watched a lot of novice
programmers, and some intermediate programmers, run into a source of
(now completely unnecessary) pain that changing this:

except ValueError:

into this:

except ValueError, TypeError:

doesn't work. Yes, it's a quick SyntaxError, but the editor won't show
it up (since most editors are Python 2 compatible, and wouldn't be
checking this level of syntax anyway), so there's X amount of time
spent coding, then go to run the thing, and it won't work the way they
expect it to.

We've had arguments like this before, and we've usually taken the position that we shouldn't compromise the language to cater to imperfect tools. Editors that are Python-aware should just catch up with Python 3 syntax. Editors that don't check this level of syntax definitely shouldn't be used as motivation at all.

(I just tried this in the latest VS Code Insiders edition, and the Python support does catch this.)

Also, I wonder what made those users think to try that? Maybe they read a tutorial or  StackOverflow issue suggesting the Python 2 syntax?
 
If it weren't for the Python 2 issues, would there be any good reason
for demanding parentheses? We don't need them in a for loop:

for i, thing in enumerate(stuff):

Someone else (Steven?) already pointed out in this thread that there are other places where 'as <target>' or 'as <identifier>' as used, the relative precedence of commas and 'as' is different than the proposal here:

  import foo.bar as foobar, bar.foo as barfoo

is parsed as

  import (foo.bar as foobar), (bar.foo as barfoo)

Similarly,

  with something as foo, something_else as bar:
      ...

is parsed as

  with (something as foo), (something_else as bar):
      ...

And similar in pattern matching.

It's true that adding "as e" makes it read oddly, but that's the only
real point against it - other than a question of "when".

I think never is a perfectly fine answer.

--
--Guido van Rossum (python.org/~guido)