[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread Chris Angelico
On Mon, May 10, 2021 at 12:49 PM Guido van Rossum  wrote:
>
> On Sun, May 9, 2021 at 5:08 PM Chris Angelico  wrote:
>>
>> On Mon, May 10, 2021 at 9:57 AM Steven D'Aprano  wrote:
>> >
>> > On Sun, May 09, 2021 at 04:45:55PM -, 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?

It's the obvious way to extend from a single exception name to two.
Think of it *without* the "as" clause and it becomes less clear that
the parentheses are necessary.

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

I think "because of the possibility of the as clause, it's not worth
doing this" is a perfectly fine answer too. It would be nice if
"except TypeError, ValueError:" could be made valid, but that may not
be worth the hassle.

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/MGWLAJKBL5EC73L3TV4VQUHI3NADNDR3/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread Guido van Rossum
On Sun, May 9, 2021 at 5:08 PM Chris Angelico  wrote:

> On Mon, May 10, 2021 at 9:57 AM Steven D'Aprano 
> wrote:
> >
> > On Sun, May 09, 2021 at 04:45:55PM -, 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 ' or 'as ' 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)
*Pronouns: he/him **(why is my pronoun here?)*

___
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/7XREC6PDF2YG55WVDXHJHWZQJNYJIC7X/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread Chris Angelico
On Mon, May 10, 2021 at 9:57 AM Steven D'Aprano  wrote:
>
> On Sun, May 09, 2021 at 04:45:55PM -, 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.

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):

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".

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/6I7XQYSNUSF76CZQBSYDYVVOXYHDOBER/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread Steven D'Aprano
On Sun, May 09, 2021 at 04:45:55PM -, 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?


-- 
Steve
___
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/KWAXL3VTUNWSDTRMQ32POXDMEPQZV42B/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread Bruce Leban
On Sun, May 9, 2021 at 1:22 PM MRAB  wrote:

>
> On the third hand(!), 'as' is used in the 'import' and 'with'
> statements, where it binds to only one preceding item.
>

Thanks. Yes, that was what I was thinking that it's weird for "as" to have
different precedence in different statements, and I should have said that
explicitly.
EIBTI of course.

--- Bruce
___
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/PNYBK5SEGYQEAL2WS62MGWW475QBD6MZ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread MRAB

On 2021-05-09 21:11, Bruce Leban wrote:



On Sun, May 9, 2021 at 9:48 AM Thomas Grainger > wrote:


now that python2.7 is EOL, it might be worth resurrecting this
syntax as discussed in
https://www.python.org/dev/peps/pep-3100/#id13


eg, python 3.11 could support
```
try:
     ...
except (E1, E2, E3) as e:
     ...
```

as equivalent to

```
try:
     ...
except E1, E2, E3 as e:
     ...
```


-1

I think you really mean you want Python to accept the form without the 
parenthesis. I don't like it because it's easy to read that as


except E1, E2, (E3 as e):

and I don't think saving two characters is worth the disruption caused 
by people being able to write Python 3.11 code that won't work in Python 
3.10. Many people would not adopt the new syntax for that reason.



I'm not keen on it either.

On the other hand, binding to e for E3 but not for E1 or E2 would be 
kind of weird, and "e = E1, E2, E3" is valid.


On the third hand(!), 'as' is used in the 'import' and 'with' 
statements, where it binds to only one preceding item.

___
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/WW7SPE25HSXTRSMM7QMXZAX4ZIXLPOTP/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread Bruce Leban
On Sun, May 9, 2021 at 9:48 AM Thomas Grainger  wrote:

> now that python2.7 is EOL, it might be worth resurrecting this syntax as
> discussed in https://www.python.org/dev/peps/pep-3100/#id13
>
> eg, python 3.11 could support
> ```
> try:
> ...
> except (E1, E2, E3) as e:
> ...
> ```
>
> as equivalent to
>
> ```
> try:
> ...
> except E1, E2, E3 as e:
> ...
> ```
>

-1

I think you really mean you want Python to accept the form without the
parenthesis. I don't like it because it's easy to read that as

except E1, E2, (E3 as e):

and I don't think saving two characters is worth the disruption caused by
people being able to write Python 3.11 code that won't work in Python 3.10.
Many people would not adopt the new syntax for that reason.

--- Bruce
___
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/7NSJP4CYS37DLKT7GZTZRO6B4CMILRJJ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread Shreyan Avigyan
+1
___
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/OEU3NVLZVFIEUIRSYONB5AQZRVMRJWF3/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread Paul Bryan
+1

On Sun, 2021-05-09 at 16:45 +, Thomas Grainger wrote:
> now that python2.7 is EOL, it might be worth resurrecting this syntax
> as discussed in https://www.python.org/dev/peps/pep-3100/#id13
> 
> eg, python 3.11 could support
> ```
> try:
>     ...
> except (E1, E2, E3) as e:
>     ...
> ```
> 
> as equivalent to 
> 
> ```
> try:
>     ...
> except E1, E2, E3 as e:
>     ...
> ```
> 
> see also
> https://mail.python.org/archives/list/python-...@python.org/thread/HSN6ESRB4BD6IUIPKLMNP4TPBQPWHBFK/
> ___
> 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/WQOMBT4Z22EIFB53WN54E52AYS3QBKAV/
> 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/GERIYIVX6XGH6JILDWSF4ISKC5IWQ3MN/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread Thomas Grainger
now that python2.7 is EOL, it might be worth resurrecting this syntax as 
discussed in https://www.python.org/dev/peps/pep-3100/#id13

eg, python 3.11 could support
```
try:
...
except (E1, E2, E3) as e:
...
```

as equivalent to 

```
try:
...
except E1, E2, E3 as e:
...
```

see also 
https://mail.python.org/archives/list/python-...@python.org/thread/HSN6ESRB4BD6IUIPKLMNP4TPBQPWHBFK/
___
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/WQOMBT4Z22EIFB53WN54E52AYS3QBKAV/
Code of Conduct: http://python.org/psf/codeofconduct/