[Python-ideas] Re: Conditional 1-line expression in python

2023-07-18 Thread Dom Grigonis
Maybe could be a part of https://peps.python.org/pep-0463/ Maybe if it was more expressive, e.g. covering the case such as you suggesting, it would go through? Also, I still don't see why changing analogous statement order when making 1-line expressions is a

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-18 Thread Dom Grigonis
Thank you. I meant “superset of 671, not 505”… One question: def bar(a => None); return foo(a) def foo(a => object()): return a How would I force foo’s default from bar’s call? Would something like this work? def foo(a => object() if a is None else a): return a > On 18 Jul 2023, a

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-18 Thread Chris Angelico
On Tue, 18 Jul 2023 at 19:02, Dom Grigonis wrote: > > Thank you. > > I meant “superset of 671, not 505”… > > One question: > > def bar(a => None); > return foo(a) > > def foo(a => object()): > return a > > How would I force foo’s default from bar’s call? That's a known-hard problem. The b

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-18 Thread Richard Damon
On 7/18/23 12:03 AM, Dom Grigonis wrote: Ok, thanks. I think what I am aiming at is that there is a pool of suggestions and PEPs that are pointing towards very similar direction and I find myself often wandering in the same space, just trying to figure out what it exactly is. It sometimes fee

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

2023-07-18 Thread Stephen J. Turnbull
Dom Grigonis writes: > I came to this, because people seem to want one-liners for certain > things and what I came up with is that maybe more concise if-else > expression could help. But "encourages one-liners" is generally considered an anti-pattern in Python. Let's see why, > # Fairly rea

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

2023-07-18 Thread Chris Angelico
On Tue, 18 Jul 2023 at 23:41, Stephen J. Turnbull wrote: > 2. Comparing floats, even against zero, is a bad idea. So I would > wrap them in math.isclose: > > val = a ? (not isclose(c, 0) ? c : d) : (not isclose(d, 0) ? d : c) That's overly simplistic; there are a lot of times when it's

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

2023-07-18 Thread Dom Grigonis
Thanks for reply, I can see most of what you have written. > But "encourages one-liners" is generally considered an anti-pattern in > Python. Let's see why, Here I am a bit confused, how is this the case in the language containing list comprehensions? I would understand if it was swapped with

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

2023-07-18 Thread Chris Angelico
On Wed, 19 Jul 2023 at 00:55, Dom Grigonis wrote: > Here I am a bit confused, how is this the case in the language containing > list comprehensions? > Do you understand the difference between expressiveness and terseness? You still seem to be focused on the completely wrong thing here. List comp

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

2023-07-18 Thread Dom Grigonis
> A plain async function pretty much IS a generator, but without the > risk of removing the last await point and having the function stop > being a generator. I am still lost in async space. From my initial benchmarking it seems that the complexity that async is introducing hardly justifies itself

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

2023-07-18 Thread Dom Grigonis
To me, they are in the inverse relationship. Terseness ~ 1 / expressiveness. Maybe I am not getting something. But surely if list comprehension took 5 lines to write, it wouldn’t be justifiable? So, even if implicit, brevity and its relation to complexity is always a factor. > On 18 Jul 2023,

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

2023-07-18 Thread Dom Grigonis
To me, saying it’s about expressiveness but not brevity sounds similar to e.g. “we are in compliance with green policies of EU, but we are not making effort to save nature.” Well, you might not consciously intend to save nature, but those who gave you presentation about green legislation had th

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

2023-07-18 Thread Paul Moore
On Tue, 18 Jul 2023 at 16:13, Dom Grigonis wrote: > To me, they are in the inverse relationship. > > Terseness ~ 1 / expressiveness. > No, they are unrelated (in general). Terseness is nothing more than "can I use fewer characters?" and is almost always the wrong thing to do in isolation (yes,

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

2023-07-18 Thread Dom Grigonis
When you put it from this perspective, it seems to make sense, however, I do not agree. To me, from first principles it seems it’s all about condensing more complexity in smaller modular packages. Leaving modularity aside, condensing more complexity in smaller packages in programming area is m

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

2023-07-18 Thread Chris Angelico
On Wed, 19 Jul 2023 at 06:41, Dom Grigonis wrote: > > When you put it from this perspective, it seems to make sense, however, I do > not agree. > > To me, from first principles it seems it’s all about condensing more > complexity in smaller modular packages. > > That is why I am a bit confused,

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

2023-07-18 Thread Dom Grigonis
Ok, fair I am confusing definitions. Expressiveness, defined by modern dictionary: “the quality of effectively conveying a thought or feeling”. Let me correct myself. Although I see that expressiveness is important, I think variable: Functionality / verbosity - can be as important. > On 18 Ju

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-18 Thread Dom Grigonis
Coming back to deferred evaluation, https://peps.python.org/pep-0671/ These 2 aren’t really orthogonal in functionality. Maybe in implementation. But PEP671 is a certain subset of deferred evaluation as it can achieve the same with 1 extra line at the start of

[Python-ideas] Re: Conditional 1-line expression in python (Dom Grigonis)

2023-07-18 Thread Chris Angelico
On Wed, 19 Jul 2023 at 11:51, Dom Grigonis wrote: > > Coming back to deferred evaluation, > > https://peps.python.org/pep-0671/ > These 2 aren’t really orthogonal in functionality. Maybe in implementation. > But PEP671 is a certain subset of deferred evaluation as it can achieve the > same with 1

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

2023-07-18 Thread Stephen J. Turnbull
Dom Grigonis writes: > > But "encourages one-liners" is generally considered an > > anti-pattern in Python. Let's see why, > Here I am a bit confused, how is this the case in the language > containing list comprehensions? I don't think of list comprehensions in terms of line count. I often