[Python-ideas] Re: Add support for private variables, methods and functions in Python

2021-05-23 Thread Marco Sulla
I think the only reason to introduce something like `private` is refactoring. If you added a `_variable` and later you decided to expose it, you have to change it to `variable`. This is something that in languages like Java is not necessary, you have only to change the variable from private to publ

[Python-ideas] Re: Add support for private variables, methods and functions in Python

2021-05-23 Thread Chris Angelico
On Sun, May 23, 2021 at 10:30 PM Marco Sulla wrote: > > I think the only reason to introduce something like `private` is > refactoring. If you added a `_variable` and later you decided to > expose it, you have to change it to `variable`. This is something that > in languages like Java is not neces

[Python-ideas] dict.get_deep()

2021-05-23 Thread Marco Sulla
I propose to add a get_deep(*args, default=_sentinel) method to dict. It can accept a single argument, that must be an iterable, or multiple arguments. The first element must be a key of the dict. If there's not a second element, the value is returned. If it's present, it tries to use it as an ar

[Python-ideas] Re: Add support for private variables, methods and functions in Python

2021-05-23 Thread Marco Sulla
On Sun, 23 May 2021 at 14:35, Chris Angelico wrote: > > On Sun, May 23, 2021 at 10:30 PM Marco Sulla > wrote: > > > > I think the only reason to introduce something like `private` is > > refactoring. If you added a `_variable` and later you decided to > > expose it, you have to change it to `vari

[Python-ideas] Re: Add support for private variables, methods and functions in Python

2021-05-23 Thread Chris Angelico
On Sun, May 23, 2021 at 10:42 PM Marco Sulla wrote: > > On Sun, 23 May 2021 at 14:35, Chris Angelico wrote: > > > > On Sun, May 23, 2021 at 10:30 PM Marco Sulla > > wrote: > > > > > > I think the only reason to introduce something like `private` is > > > refactoring. If you added a `_variable` a

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

2021-05-23 Thread Shivam Saini
Sometimes, we need to execute a statement, which might throw an exception and we want to return None if it causes an exception. In short, we want to run that command as failsafe mode, so that it doesn't cause abnormal termination in case of any exception. *Approach till now:* def log_to_telegram(

[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 m

[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 an

[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): @wraps(

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread Thomas Grainger
seems a bit like https://www.python.org/dev/peps/pep-0505/ eg `d?[1]?[0]` ___ 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.or

[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 alr

[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 swallow(*e

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread Marco Sulla
On Sun, 23 May 2021 at 15:30, Thomas Grainger wrote: > > seems a bit like https://www.python.org/dev/peps/pep-0505/ > > eg `d?[1]?[0]` No, I do not want to suppress the exception, only to have a way to access a nested object in a complicate dict, for example a dict generated by a JSON. In your e

[Python-ideas] Re: Add support for private variables, methods and functions in Python

2021-05-23 Thread Marco Sulla
On Sun, 23 May 2021 at 14:50, Chris Angelico wrote: > > On Sun, May 23, 2021 at 10:42 PM Marco Sulla > wrote: > > > > On Sun, 23 May 2021 at 14:35, Chris Angelico wrote: > > > > > > On Sun, May 23, 2021 at 10:30 PM Marco Sulla > > > wrote: > > > > > > > > I think the only reason to introduce so

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread MRAB
On 2021-05-23 13:37, Marco Sulla wrote: I propose to add a get_deep(*args, default=_sentinel) method to dict. It can accept a single argument, that must be an iterable, or multiple arguments. The first element must be a key of the dict. If there's not a second element, the value is returned. If

[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 your

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread Chris Angelico
On Mon, May 24, 2021 at 1:24 AM MRAB wrote: > Also, if the first lookup returns a list or a tuple, and an argument can > be an index of that list, would be make sense to add a similar method to > lists and tuples? Or, better: make it a stand-alone function, not a method of anything. Although that

[Python-ideas] Re: Add support for private variables, methods and functions in Python

2021-05-23 Thread 2QdxY4RzWzUUiLuE
On 2021-05-23 at 16:30:35 +0200, Marco Sulla wrote: > On Sun, 23 May 2021 at 14:50, Chris Angelico wrote: > > > > On Sun, May 23, 2021 at 10:42 PM Marco Sulla > > wrote: > > > > > > On Sun, 23 May 2021 at 14:35, Chris Angelico wrote: > > > > > > > > On Sun, May 23, 2021 at 10:30 PM Marco Sulla

[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 y

[Python-ideas] Re: Add support for private variables, methods and functions in Python

2021-05-23 Thread Abdur-Rahmaan Janhangeer
Greetings list, This whole thread reminds me of a comment of Miguel Grinberg i remember somewhere when discussing secrets. Some go for .env some for env variables but he suggested focusing the attention on not letting people getting access to the server instead of trying to be clever about hiding

[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 o

[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-le..

[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 suppress(Except

[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. ___ Pytho

[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 feat

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread Marco Sulla
On Sun, 23 May 2021 at 17:22, MRAB wrote: > > On 2021-05-23 13:37, Marco Sulla wrote: > > I propose to add a get_deep(*args, default=_sentinel) method to dict. > > > > It can accept a single argument, that must be an iterable, or multiple > > arguments. > > > > The first element must be a key of t

[Python-ideas] Re: Add support for private variables, methods and functions in Python

2021-05-23 Thread Marco Sulla
On Sun, 23 May 2021 at 17:43, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2021-05-23 at 16:30:35 +0200, > Marco Sulla wrote: > > > On Sun, 23 May 2021 at 14:50, Chris Angelico wrote: > > > > > > On Sun, May 23, 2021 at 10:42 PM Marco Sulla > > > wrote: > > > > > > > > On Sun, 23 May 2021

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread Todd
The pytoolz/cytoolz project already has this: https://toolz.readthedocs.io/en/latest/api.html#toolz.dicttoolz.get_in On Sun, May 23, 2021, 11:44 Chris Angelico wrote: > On Mon, May 24, 2021 at 1:24 AM MRAB wrote: > > Also, if the first lookup returns a list or a tuple, and an argument can > > b

[Python-ideas] Re: Add support for private variables, methods and functions in Python

2021-05-23 Thread Chris Angelico
On Mon, May 24, 2021 at 3:38 AM Marco Sulla wrote: > > > > Do you yearn for actual refactoring tools - which do exist? > > > > > > Renaming tools of IDE do not work in 100% of the cases. For example, > > > if you have _variable in an eval string, it's not replaced. > > > > Another reason not to us

[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 -- pyth