[Python-ideas] Re: for ... except, with ... except

2019-07-31 Thread Guido van Rossum
On Wed, Jul 31, 2019 at 2:06 AM Rob Cliffe via Python-ideas < python-ideas@python.org> wrote: > > > On 31/07/2019 00:35:59, Eric V. Smith wrote: > >> On Jul 30, 2019, at 11:38 AM, Guido van Rossum > wrote: > >> > > .. > > > >> with connect() as stream: # connect() or __enter__() can fail.

[Python-ideas] Re: for ... except, with ... except

2019-07-31 Thread Geoffrey Spear
On Tue, Jul 30, 2019 at 6:04 PM Greg Ewing wrote: > Something I don't like about these kinds of proposals is that > the except clause is far removed from the code that it covers, > hurting readability. By the time you get to the end of a big > for-loop or with-statement and see an "except", it's

[Python-ideas] Re: for ... except, with ... except

2019-07-31 Thread Rob Cliffe via Python-ideas
On 31/07/2019 00:35:59, Eric V. Smith wrote: On Jul 30, 2019, at 11:38 AM, Guido van Rossum wrote: .. with connect() as stream: # connect() or __enter__() can fail. for data in stream: # __next__() can fail write(data) # write() can fail This very much l

[Python-ideas] Re: for ... except, with ... except

2019-07-31 Thread Rob Cliffe via Python-ideas
On 30/07/2019 23:37:38, Greg Ewing wrote: Guido van Rossum wrote: I'm not sure I understand the desire to catch every possible exception right where it occurs. I've never felt this need somehow. This is my feeling too. I can't remember having a need for such needle-sharp targeting of excepti

[Python-ideas] Re: for ... except, with ... except

2019-07-30 Thread Eric V. Smith
> On Jul 30, 2019, at 11:38 AM, Guido van Rossum wrote: > ... > > with connect() as stream: # connect() or __enter__() can fail. > for data in stream: # __next__() can fail > write(data) # write() can fail > > This very much looks like toy networking code to me

[Python-ideas] Re: for ... except, with ... except

2019-07-30 Thread Greg Ewing
Guido van Rossum wrote: I'm not sure I understand the desire to catch every possible exception right where it occurs. I've never felt this need somehow. This is my feeling too. I can't remember having a need for such needle-sharp targeting of exception catching, and if I ever did, it would be s

[Python-ideas] Re: for ... except, with ... except

2019-07-30 Thread Greg Ewing
Something I don't like about these kinds of proposals is that the except clause is far removed from the code that it covers, hurting readability. By the time you get to the end of a big for-loop or with-statement and see an "except", it's easy to forget that it isn't attached to an ordinary try-st

[Python-ideas] Re: for ... except, with ... except

2019-07-30 Thread Guido van Rossum
On Tue, Jul 30, 2019 at 1:13 AM Paul Moore wrote: > On Tue, 30 Jul 2019 at 04:00, Ethan Furman wrote: > > If this "with...except" leads to more robust code then I think many > would like to use it, but not if it's confusing as that would lead to less > robust code. > > For me, "it's for robust c

[Python-ideas] Re: for ... except, with ... except

2019-07-30 Thread Jonathan Goble
On Tue, Jul 30, 2019 at 9:32 AM Rhodri James wrote: > I've been trying to come up > with something more like this: > >with something_exceptionable() as f: >do_something_with(f) >except with SomeException as e: >handle_exception_in_setup_or_teardown(e) >except SomeOtherE

[Python-ideas] Re: for ... except, with ... except

2019-07-30 Thread Rhodri James
On 30/07/2019 02:35, Steven D'Aprano wrote: On Mon, Jul 29, 2019 at 03:12:21PM +0100, Rhodri James wrote: I'm afraid I agree with Guido. I don't imagine I will use this feature very often, and I can see myself making that mistake every time. Well, if you don't use this feature very often, yo

[Python-ideas] Re: for ... except, with ... except

2019-07-30 Thread Paul Moore
On Tue, 30 Jul 2019 at 04:00, Ethan Furman wrote: > If this "with...except" leads to more robust code then I think many would > like to use it, but not if it's confusing as that would lead to less robust > code. For me, "it's for robust code" is sufficient hint that I now remember what it does

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Ethan Furman
On 07/29/2019 06:35 PM, Steven D'Aprano wrote: 3. syntax that solves a problem, but may mislead people to think it solves a different problem until they learn better; 3.1 syntax that solves a problem, but is misleading to many who are still confused after they "have learnt better" I

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Andrew Barnert via Python-ideas
On Jul 29, 2019, at 14:49, Guido van Rossum wrote: > > Still I wouldn't call this "a lot worse". What makes you say that? Not “worse” as in more common, or more dangerous (I don’t know if that’s true or not), but as in harder to work around. for…else being confusing and effectively “experts o

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Steven D'Aprano
On Fri, Jul 26, 2019 at 09:26:00PM +0300, Serhiy Storchaka wrote: > Python allows you to write code in tight and readable form. Consider the > following example. > > with connect() as stream: # connect() or __enter__() can fail. > for data in stream: # __next__() can fail >

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Steven D'Aprano
On Mon, Jul 29, 2019 at 03:12:21PM +0100, Rhodri James wrote: > I'm afraid I agree with Guido. I don't imagine I will use this feature > very often, and I can see myself making that mistake every time. Well, if you don't use this feature very often, you aren't really the audience for the featu

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Rob Cliffe via Python-ideas
On 30/07/2019 00:07:52, Guido van Rossum wrote: On Mon, Jul 29, 2019 at 3:51 PM Eric Fahlgren > wrote: On Mon, Jul 29, 2019 at 2:58 PM Guido van Rossum mailto:gu...@python.org>> wrote: I am *guessing* the problem here is something like this:

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Guido van Rossum
On Mon, Jul 29, 2019 at 3:51 PM Eric Fahlgren wrote: > On Mon, Jul 29, 2019 at 2:58 PM Guido van Rossum wrote: > >> I am *guessing* the problem here is something like this: >> >> with open(filename) as f: >> data = f.read() >> >> raises an exception if the open() call fails, but putting try.

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Eric Fahlgren
On Mon, Jul 29, 2019 at 2:58 PM Guido van Rossum wrote: > I am *guessing* the problem here is something like this: > > with open(filename) as f: > data = f.read() > > raises an exception if the open() call fails, but putting try... except > IOError: ... around the whole thing also catches I/O

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Guido van Rossum
On Mon, Jul 29, 2019 at 2:36 PM Andrew Barnert via Python-ideas < python-ideas@python.org> wrote: > On Jul 29, 2019, at 12:24, Dominik Vilsmeier > wrote: > > > > I could imagine that due to the awkward workaround, especially regarding > `with`, corresponding "self-made" code is either error-prone

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Andrew Barnert via Python-ideas
On Jul 29, 2019, at 12:24, Dominik Vilsmeier wrote: > > I could imagine that due to the awkward workaround, especially regarding > `with`, corresponding "self-made" code is either error-prone or people will > not even try to work around it in the first place. This feature will probably > be am

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Guido van Rossum
Sorry, that does not convince me. You're assuming that everybody is a language designer. Many Python users actually have little language design sense, and you shouldn't need to have it in order to be able to use the language. People are productive by learning to recognize and copy patterns, but th

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Ethan Furman
On 07/29/2019 12:24 PM, Dominik Vilsmeier wrote: I think the focus shouldn't be on whether such syntax is possibly confusing or not because a) People will always remember that's *either* one way or the other No, they won't. b) It's actually pretty easy to remember which way it is, by just

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Dominik Vilsmeier
I think the focus shouldn't be on whether such syntax is possibly confusing or not because a) People will always remember that's *either* one way or the other, but are very unlikely to just assume one; hence they can always check what it does, and more importantly, b) It's actually pretty easy

[Python-ideas] Re: for ... except, with ... except

2019-07-29 Thread Rhodri James
On 27/07/2019 09:19, Serhiy Storchaka wrote: 26.07.19 23:57, Guido van Rossum пише: These are interesting ideas. It looks like you intend the except clause of the for loop to *only* cover the iter() and next() calls that are implicit in the for loop. You're right that it's awkward to catch exc

[Python-ideas] Re: for ... except, with ... except

2019-07-28 Thread Ethan Furman
[redirecting back to the list] On 07/27/2019 09:38 PM, James Lu wrote: On Jul 27, 2019, at 12:44 PM, Ethan Furman wrote: Sure, folks /know/ what it means, but it's a common bug because it doesn't read as "if some_var is assigned 7" but as "if some_var is equal to 7". That’s a straw man- a

[Python-ideas] Re: for ... except, with ... except

2019-07-27 Thread Ethan Furman
On 07/27/2019 01:19 AM, Serhiy Storchaka wrote: 26.07.19 23:57, Guido van Rossum пише: However, I worry that when people see this syntax, they will think that the except clause is for handling exceptions in the loop body. (That's certainly what I assumed when I read just your subject line. :

[Python-ideas] Re: for ... except, with ... except

2019-07-27 Thread Anders Hovmöller
> On 27 Jul 2019, at 10:19, Serhiy Storchaka wrote: > > 26.07.19 23:57, Guido van Rossum пише: >> These are interesting ideas. It looks like you intend the except clause of >> the for loop to *only* cover the iter() and next() calls that are implicit >> in the for loop. You're right that it's

[Python-ideas] Re: for ... except, with ... except

2019-07-27 Thread Serhiy Storchaka
26.07.19 21:52, Bruce Leban пише: On Fri, Jul 26, 2019 at 11:27 AM Serhiy Storchaka > wrote: So you will be able to add errors handling like in:      with connect() as stream:          for data in stream:              try:                  writ

[Python-ideas] Re: for ... except, with ... except

2019-07-27 Thread Serhiy Storchaka
26.07.19 23:57, Guido van Rossum пише: These are interesting ideas. It looks like you intend the except clause of the for loop to *only* cover the iter() and next() calls that are implicit in the for loop. You're right that it's awkward to catch exceptions there. Right. If you want to catch a

[Python-ideas] Re: for ... except, with ... except

2019-07-27 Thread Serhiy Storchaka
26.07.19 23:46, MRAB пише: On 2019-07-26 19:26, Serhiy Storchaka wrote: [snip] I propose to add "except" clause to "for" and "with" statement to catch exceptions in the code that can't be wrapped with "try ... except".   for VAR in EXPR:   BLOCK   except EXC:   HANDLER

[Python-ideas] Re: for ... except, with ... except

2019-07-26 Thread Guido van Rossum
These are interesting ideas. It looks like you intend the except clause of the for loop to *only* cover the iter() and next() calls that are implicit in the for loop. You're right that it's awkward to catch exceptions there. However, I worry that when people see this syntax, they will think that th

[Python-ideas] Re: for ... except, with ... except

2019-07-26 Thread MRAB
On 2019-07-26 19:26, Serhiy Storchaka wrote: [snip] I propose to add "except" clause to "for" and "with" statement to catch exceptions in the code that can't be wrapped with "try ... except". for VAR in EXPR: BLOCK except EXC: HANDLER should be equivalent to

[Python-ideas] Re: for ... except, with ... except

2019-07-26 Thread Andrew Barnert via Python-ideas
On Jul 26, 2019, at 11:26, Serhiy Storchaka wrote: > > I propose to add "except" clause to "for" and "with" statement to catch > exceptions in the code that can't be wrapped with "try ... except". > >for VAR in EXPR: >BLOCK >except EXC: >HANDLER I’m pretty sure for…exce