[Python-ideas] Re: Proposal for get_or function in Python dictionaries

2023-07-10 Thread Dom Grigonis
I like this. Something that I would use for sure. I have used a lot of: ``` (value: None | object ) or default ``` , but I stopped for obvious reasons. However, I miss those days, when I was ignorant that this is not a good idea. > On 11 Jul 2023, at 01:17, David Mertz, Ph.D. wrote: > >

[Python-ideas] Re: Proposal for get_or function in Python dictionaries

2023-07-10 Thread Dom Grigonis
This feels superfluous. Instead of creating new dict class I would propose either: 1. Not to have None values a) It is most likely possible to pre-delete all None values before you use the dict = {k: v for k, v in dict if v is not None} b) Not to create them in the first place (if it depends

[Python-ideas] Re: Proposal for get_or function in Python dictionaries

2023-07-10 Thread David Mertz, Ph.D.
This is basically PEP 505 – None-aware operators ( https://peps.python.org/pep-0505/). I've generally been opposed to that, but clearly some serious and smart Pythonistas have supported it. That PEP is a bigger lift than your suggestion, but correspondingly more general. On Mon, Jul 10, 2023,

[Python-ideas] Re: Proposal for get_or function in Python dictionaries

2023-07-10 Thread Chris Angelico
On Tue, 11 Jul 2023 at 08:05, Jothir Adithyan wrote: > Assumptions: > > The problem statement is based on a few assumptions: > - You prefer chaining `get` statements for cleaner code. > - You expect at least some of the `get` methods to return `None`. > - You want to avoid the hassle of using

[Python-ideas] Proposal for get_or function in Python dictionaries

2023-07-10 Thread Jothir Adithyan
Hi everyone, I would like to briefly present my idea regarding the `get` function commonly used with dictionaries. When working with large amounts of JSON data, I often encounter code that doesn't feel very Pythonic to me. Problem Statement: The `get` function allows chaining of