[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-10 Thread Stephen J. Turnbull
Serhiy Storchaka writes: > A year or two ago I proposed the same syntax with different semantic: to > catch only exceptions in the context manager, not in the with > block. FWIW, this is the semantics I would expect, for the reason you give: > Exceptions in the with block you can catch by ad

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-10 Thread Serhiy Storchaka
09.04.21 21:02, Guido van Rossum пише: > But if there are two proposals with conflicting semantics for the same > syntax that kills both ideas, doesn’t it? Because apparently it’s not > clear what the syntax should mean. Maybe. But there was also different idea for the "with" statement (with seman

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-09 Thread Mike Miller
On 2021-04-08 11:25, Chris Angelico wrote: On Fri, Apr 9, 2021 at 2:24 AM Paul Bryan wrote: Q. Safe to assume this would catch exceptions from both the call to `open` as well as the call to `open.__enter__`? No, not safe to assume. It's equally reasonable to define it as guarding only the

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-09 Thread Ethan Furman
On 4/9/21 11:33 AM, anthony.flury via Python-ideas wrote: On 09/04/2021 19:02, Guido van Rossum wrote: But if there are two proposals with conflicting semantics for the same syntax that kills both ideas, doesn’t it? Because apparently it’s not clear what the syntax should mean. Surely it dep

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-09 Thread anthony.flury via Python-ideas
On 09/04/2021 19:02, Guido van Rossum wrote: But if there are two proposals with conflicting semantics for the same syntax that kills both ideas, doesn’t it? Because apparently it’s not clear what the syntax should mean. Surely it depends (if we adopt a proposal) how we document it. You could

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-09 Thread Guido van Rossum
But if there are two proposals with conflicting semantics for the same syntax that kills both ideas, doesn’t it? Because apparently it’s not clear what the syntax should mean. On Fri, Apr 9, 2021 at 00:28 Serhiy Storchaka wrote: > 08.04.21 17:59, anthony.flury via Python-ideas пише: > > I was wo

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-09 Thread Serhiy Storchaka
08.04.21 17:59, anthony.flury via Python-ideas пише: > I was wondering whether a worthwhile extension might be to allow the > `with` statement to have an `except` and  `else` clauses which would > have the same > semantics as wrapping the `with` block with a try - for example the > above would now

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-08 Thread Christopher Barker
My application-level > exception handling is rarely that close to the file operations, > it's usually at a much higher level. With is used for lots of other things, too. Does this same point apply to other use cases? For my part, I still find the extra indentation annoying required for with to

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-08 Thread Chris Angelico
On Fri, Apr 9, 2021 at 8:22 AM Ethan Furman wrote: > > On 4/8/21 2:40 PM, Chris Angelico wrote: > > > At least in this form, it's clear that there's a sharp distinction > > between the stuff around the outside of the 'with' block and the stuff > > inside it. > > > > The semantics, as suggested, gi

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-08 Thread Greg Ewing
On 9/04/21 2:59 am, anthony.flury via Python-ideas wrote: I was wondering whether a worthwhile extension might be to allow the `with` statement to have an `except` and `else` clauses I don't think I would find this very useful. My application-level exception handling is rarely that close to the

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-08 Thread Ethan Furman
On 4/8/21 2:40 PM, Chris Angelico wrote: At least in this form, it's clear that there's a sharp distinction between the stuff around the outside of the 'with' block and the stuff inside it. The semantics, as suggested, give 'with' blocks two distinct exception-management scopes, which mostly bu

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-08 Thread Chris Angelico
On Fri, Apr 9, 2021 at 6:41 AM Ethan Furman wrote: > > On 4/8/21 1:21 PM, Chris Angelico wrote: > > On Fri, Apr 9, 2021 at 6:16 AM Ethan Furman wrote: > >> On 4/8/21 11:25 AM, Chris Angelico wrote: > > >>> Similar question: What would be the semantics of this? > >>> > >>> with contextlib.suppress(

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-08 Thread Ethan Furman
On 4/8/21 1:21 PM, Chris Angelico wrote: On Fri, Apr 9, 2021 at 6:16 AM Ethan Furman wrote: On 4/8/21 11:25 AM, Chris Angelico wrote: Similar question: What would be the semantics of this? with contextlib.suppress(BaseException): a = b / c except BaseException as e: print(e) Wha

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-08 Thread Chris Angelico
On Fri, Apr 9, 2021 at 6:16 AM Ethan Furman wrote: > > On 4/8/21 11:25 AM, Chris Angelico wrote: > > > Similar question: What would be the semantics of this? > > > > with contextlib.suppress(BaseException): > > a = b / c > > except BaseException as e: > > print(e) > > > > What types of e

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-08 Thread Ethan Furman
On 4/8/21 11:25 AM, Chris Angelico wrote: Similar question: What would be the semantics of this? with contextlib.suppress(BaseException): a = b / c except BaseException as e: print(e) What types of exception could be caught and what types couldn't? Well, if every exception is deriv

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-08 Thread Chris Angelico
On Fri, Apr 9, 2021 at 1:38 AM anthony.flury via Python-ideas wrote: > ... indented twice just to accommodate the outer try block. > > Treating the 'with' as an implied `try` would reduce the march to the right - > now the key processing of the resource is now indented only one level - and > the

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-08 Thread Paul Bryan
I think I like it. Q. Safe to assume this would catch exceptions from both the call to `open` as well as the call to `open.__enter__`? Q. What about something even more verbose (descriptive) like`try with open(...) as cfg:`?  🙂 Paul On Thu, 2021-04-08 at 15:59 +0100, anthony.flury via Python-i

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-08 Thread Jonathan Goble
On Thu, Apr 8, 2021, 11:39 AM anthony.flury via Python-ideas < python-ideas@python.org> wrote: > I was wondering whether a worthwhile extension might be to allow the > `with` statement to have an `except` and `else` clauses which would have > the same > > semantics as wrapping the `with` block wi