[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Irit Katriel via Python-ideas
On Sunday, May 23, 2021, 02:23:05 PM GMT+1, Shivam Saini wrote: >> Like the first example in which I am sending an log, which isn't important.  If the log is not important, then why are you sending it? ___ Python-ideas mailing list --

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Serhiy Storchaka
23.05.21 12:42, Shivam Saini пише: >     except: >         pass Don't do this. Never write a bare except handler which does not re-raise an exception. There are few exceptions of this rule, but it is unlikely that you will see them in first years of your practice. It is an anti-pattern, and a

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Serhiy Storchaka
23.05.21 16:22, Shivam Saini пише: > After all, python is known for one liners It is not Python that is known for one liners. Python syntax is rather opposed to one liners. It encourages and sometimes forces a user to write well-indented code. ___

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Ricky Teachey
On Sun, May 23, 2021, 12:02 PM Damian Shaw wrote: > FYI, > > Something very similar already exists in the standard library, > contextlib.suppress: > https://docs.python.org/3/library/contextlib.html#contextlib.suppress > > It makes a nice 2+ liner for a lot of situations: > > with

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Ricky Teachey
On Sun, May 23, 2021, 9:35 AM Stestagg wrote: > FYI, default here is unused. > Thanks! Yes I had put that at the first and intended to remove it. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread 2QdxY4RzWzUUiLuE
On 2021-05-24 at 01:34:29 +1000, Steven D'Aprano wrote: > On Sun, May 23, 2021 at 06:52:38PM +0530, Shivam Saini wrote: > > > After all, python is known for one liners and this would be an another > > great one liner if implemented. > > Python isn't known for one-liners. You might be thinking

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Damian Shaw
FYI, Something very similar already exists in the standard library, contextlib.suppress: https://docs.python.org/3/library/contextlib.html#contextlib.suppress It makes a nice 2+ liner for a lot of situations: with suppress(Exception): ... Seems more flexible than OPs keyword suggestion as

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Steven D'Aprano
On Sun, May 23, 2021 at 06:52:38PM +0530, Shivam Saini wrote: > After all, python is known for one liners and this would be an another > great one liner if implemented. Python isn't known for one-liners. You might be thinking of Perl. Being known for one-liners is a bad thing. It means that

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Stestagg
FYI, default here is unused. On Sun, 23 May 2021 at 14:29, Ricky Teachey via Python-ideas < python-ideas@python.org> wrote: > I think you can already do all of this with a custom exception-swallowing > decorator function. > > Something like this: > > from functools import wraps > > def

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Shivam Saini
That wont be an oneliner still. We can add decorator to a function, and that don't even be very readable. If we can convert that decorator to an inbuilt keyword that would work as an one liner and would be very readable too. On Sun, 23 May 2021, 18:56 Ricky Teachey, wrote: > I think you can

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Ricky Teachey via Python-ideas
I think you can already do all of this with a custom exception-swallowing decorator function. Something like this: from functools import wraps def swallow(*exceptions, default=Exception, result=None): if not exceptions: exceptions = Exception, def decorator(func):

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Shivam Saini
That's what I think it should be for. I know safe open(...) isn't a really good example for this, but I had just used that for demonstration purposes. Instead what I am saying is that sometimes we just don't care even if an statement raises exception. Like the first example in which I am sending

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Thomas Grainger
sounds very much like https://www.python.org/dev/peps/pep-0463/#rejection-notice I'm concerned with the `safe` defaulting to a bare `except:` which will also catch CancelledError other errors that should be re-raised also ``` file = safe open('some_file') ``` does not provide a way to