[Python-ideas] Re: commonprefix

2024-06-12 Thread Dom Grigonis
This being in `os.path` module suggests that the main intent is to find a common prefix of a `path`. If this is the case, maybe it would be worth instead of: ``` if not isinstance(m[0], (list, tuple)): m = tuple(map(os.fspath, m)) ``` have ``` if not isinstance(m[0], (list, tuple)):

[Python-ideas] Re: Descriptor __get__ and __set__ argument discrepancy

2023-10-19 Thread Dom Grigonis
he class-attribute and not call the descriptor), so instance > can never be None and owner is type(instance). > > Le jeu. 19 oct. 2023 à 09:45, Dom Grigonis <mailto:dom.grigo...@gmail.com>> a écrit : > > > On 19 Oct 2023, at 10:27, dn via Python-ideas > <mailto:python-

[Python-ideas] Re: Descriptor __get__ and __set__ argument discrepancy

2023-10-19 Thread Dom Grigonis
> On 19 Oct 2023, at 10:27, dn via Python-ideas wrote: > > On 19/10/2023 19.50, Dom Grigonis wrote: >> Thank you, >> Good information, thank you. Was not aware of __set_name__. > > IIRC that was one of the updates/improvements. Thanks to whomsoever...! > > T

[Python-ideas] Re: Descriptor __get__ and __set__ argument discrepancy

2023-10-18 Thread Dom Grigonis
Thank you, Good information, thank you. Was not aware of __set_name__. DG > On 19 Oct 2023, at 09:28, dn via Python-ideas wrote: > > On 19/10/2023 18.29, Dom Grigonis wrote: >> def __get__(self, instance, owner): >> def __set__(self, instance, value): >> Is there

[Python-ideas] Descriptor __get__ and __set__ argument discrepancy

2023-10-18 Thread Dom Grigonis
Hi all, Quick question. def __get__(self, instance, owner): def __set__(self, instance, value): Is there a reason why `__set__` does not have owner in it’s arguments while `__get__` does? Regards, DG ___ Python-ideas mailing list -- python-ideas@pyt

[Python-ideas] Non-aware operators PEP505

2023-10-15 Thread Dom Grigonis
Hi all, Just want to follow up on discussions from before by saying that I came to a conclusion that from my POV non-aware operators would be an excellent addition to python. The number of times that I need to write: pal = None if self.pal is None else self.pal.rgb_to_cmy() or alternatively: pa

[Python-ideas] Re: SyntaxError: cannot use assignment expressions with attribute

2023-10-09 Thread Dom Grigonis
True: line = f.readline() if line and check(line): process(line) else: break DG > On 9 Oct 2023, at 15:52, Stephen J. Turnbull > wrote: > > Dom Grigonis writes: > >> Mistake, late night. I just meant to portray initialisation via

[Python-ideas] Re: SyntaxError: cannot use assignment expressions with attribute

2023-10-08 Thread Dom Grigonis
On 9 Oct 2023, at 08:58, Stephen J. Turnbull wrote: > ... > Not sure what you're getting at here, that's an infloop. Did you mean > something like this: > >class A: >def func(self): >while (self.a := self.a += 1) < 5: >pass >return self.a Mist

[Python-ideas] Re: SyntaxError: cannot use assignment expressions with attribute

2023-10-08 Thread Dom Grigonis
> Having: > >self.mode = self.mode_valid(mode) >return self.mode > > isn't too bad. No, not bad at all. But to me, being able to use walrus would be convenient. ——— This nuance can also be encountered in “principal use-case”. E.g.: class A: def func(self): while (self.a :=

[Python-ideas] SyntaxError: cannot use assignment expressions with attribute

2023-10-08 Thread Dom Grigonis
Is there a reason why this is not allowed? return (self.mode := self.mode_valid(mode)) ___ 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-ide

[Python-ideas] Re: Extract variable name from itself

2023-09-28 Thread Dom Grigonis
red to was not offensive, only unless badly misinterpreted. An accusation as such on a public group is. It was also offensive to people who you implicitly involved in supposedly supporting your opinion without their consent. Regards, DG > Em dom., 24 de set. de 2023 às 21:06, Dom Grigonis <

[Python-ideas] Re: Extract variable name from itself

2023-09-25 Thread Dom Grigonis
I think a lot has been said by this time and I have nothing to add. If this is something that is of value, I am sure it will be picked up when the time is right. One last thing that I think could be of some use is a poll: https://take.supersurvey.com/QCVZKTDY0

[Python-ideas] Re: Extract variable name from itself

2023-09-24 Thread Dom Grigonis
What is your position on this? Do you think that such thing is worth having? If yes, do any of the 3 final options seem sensible to you? > On 25 Sep 2023, at 02:39, Chris Angelico wrote: > > On Mon, 25 Sept 2023 at 07:05, Dom Grigonis wrote: >> What I meant is that functions

[Python-ideas] Re: Extract variable name from itself

2023-09-24 Thread Dom Grigonis
After all, f’{v!}’ applies functions to v from builtin namespace: str/repr/ascii. > Em dom., 24 de set. de 2023 às 16:11, Dom Grigonis <mailto:dom.grigo...@gmail.com>> escreveu: > > >> On 24 Sep 2023, at 19:27, Tiago Illipronti Girardi > <mailto:tiago

[Python-ideas] Re: Extract variable name from itself

2023-09-24 Thread Dom Grigonis
ue functionality providing things, such as id, type, exec, etc. > While I would be very glad if my opinion is adopted by the community, do not > substitute my opinion for the community's. > > Em dom., 24 de set. de 2023 às 12:29, Dom Grigonis <mailto:dom.grigo...@gmail.com

[Python-ideas] Re: Extract variable name from itself

2023-09-24 Thread Dom Grigonis
ldn't change the interpreter at all, (but would change the stdlib). > > Either way, the 'nameof'-support needs editor support, because it is an > *editing* use case, the interpreter just doesn't care. > (It could, but it *can't* do anything without the *

[Python-ideas] Re: Extract variable name from itself

2023-09-24 Thread Dom Grigonis
> On 24 Sep 2023, at 17:23, Chris Angelico wrote: > > On Mon, 25 Sept 2023 at 00:15, Dom Grigonis wrote: >> I see what you mean, but this property is arguably intrinsic to what it is. >> And is part of f-strings vs explicit formatting property too: >> >>

[Python-ideas] Re: Extract variable name from itself

2023-09-24 Thread Dom Grigonis
> On 24 Sep 2023, at 16:42, Stephen J. Turnbull > wrote: > > Dom Grigonis writes: > >>> But it's far from concise >> What could be more concise? > > A notation where you don't have to repeat a possibly long expression. > For example, numeri

[Python-ideas] Re: Extract variable name from itself

2023-09-24 Thread Dom Grigonis
> But it's far from concise What could be more concise? > and > violates DRY -- it doesn't solve the problem of the first draft typo. And how is “postfix =“ different? > I don't see it as elegant the way "postfix =" is. Agreed. DG ___ Python-ideas mai

[Python-ideas] Re: Extract variable name from itself

2023-09-23 Thread Dom Grigonis
t the benefits of it being well integrated python construct, which is subject to a parser and is a python code by all standards and it fitting in that place sensibly given what it is. Regards, DG > On 24 Sep 2023, at 05:15, Stephen J. Turnbull > wrote: > > Dom Grigonis writes: >

[Python-ideas] Re: Extract variable name from itself

2023-09-23 Thread Dom Grigonis
cost. No, I don’t think that. I wrote here to find that out. What I think is that it would be an elegant feature if it was implemented at python level. Thanks for reply, DG > On 24 Sep 2023, at 02:24, Eric V. Smith wrote: > >  > >> On Sep 23, 2023, at 5:37 PM, Dom Grigonis w

[Python-ideas] Re: Extract variable name from itself

2023-09-23 Thread Dom Grigonis
So it does seem that it can be done manageably, while all editors with f-string support would benefit instantaneously without extra effort or unnecessary complications such as `typing` library. Regards, DG > On 23 Sep 2023, at 23:55, Dom Grigonis wrote: > >> the output will have t

[Python-ideas] Re: Extract variable name from itself

2023-09-23 Thread Dom Grigonis
> If you pay close attention to the execution model > <https://docs.python.org/3/reference/executionmodel.html#naming-and-binding> > there is a link from the name to the object but not the other way around, so > you can't get it from the object. That's it.

[Python-ideas] Re: Extract variable name from itself

2023-09-23 Thread Dom Grigonis
t everyone uses it or even needs to know it. DG —Evaluation of deferred evaluation can be deferred, but not indefinitely — > Em sáb., 23 de set. de 2023 às 09:51, Dom Grigonis <mailto:dom.grigo...@gmail.com>> escreveu: >> This is the only use case I can think of. > Yes, probab

[Python-ideas] Re: Extract variable name from itself

2023-09-23 Thread Dom Grigonis
> This is the only use case I can think of. Yes, probably most common one, but I have mentioned couple more. 1. Keeping dictionary keys in sync with variable name. 2. eval / exec statements. Although eval / exec are not recommended in high standard production code, python is widely used in plugin

[Python-ideas] Re: Extract variable name from itself

2023-09-23 Thread Dom Grigonis
> On 23 Sep 2023, at 08:54, Stephen J. Turnbull > wrote: > > Dom Grigonis writes: > >> Simply eval/exec string inputs. I sometimes use of these for ad-hoc >> callbacks. Would be great if `v` was recognised as a code. > > Looking at the example, do you mea

[Python-ideas] Re: Extract variable name from itself

2023-09-22 Thread Dom Grigonis
lif isinstance(smtp, str): self.d[k] = eval(f'{=v}{smtp}') a = A() print(a.d)# {'a': 1, 'b': 2} a.apply(lambda x: x * 2) print(a.d)# {'a': 2, 'b': 4} a.apply('* 2') print(a.d)

[Python-ideas] Re: Revise using the colon ( : )

2023-09-20 Thread Dom Grigonis
My bad, you have pointed to ambiguity accurately. Thanks for taking time to correct me. Regards, DG > On 20 Sep 2023, at 16:09, Celelibi wrote: > > 2023-09-12 7:10 UTC+02:00, Dom Grigonis : >> I don’t think your example depicts the ambiguity well. >> >> 1. is

[Python-ideas] Re: Extract variable name from itself

2023-09-18 Thread Dom Grigonis
Thank you Jonathan, This is indeed helpful, I have completely forgotten about these. However, in my case, defaults are not callable defaults, but rather default values preset at a higher level object and it has little to do with function defaults. Although, I think it is possible to reshape th

[Python-ideas] Re: Extract variable name from itself

2023-09-17 Thread Dom Grigonis
Thank you Jonathan, Could you please elaborate on your suspicion, that my proposed addition will make bad code easier to write? It would be nice if you provided example, where there is a pattern using my proposed addition, where similar badness of code cant be achieved using already existing p

[Python-ideas] Re: Extract variable name from itself

2023-09-16 Thread Dom Grigonis
Hi Jonathan, I wasn’t writing anything specialised on handling of defaults. My initial example pretty much covers it. What defaults handler of python are you talking about? This proposal is more about convenient refactoring and keeping things nicely synchronised where variable name and string

[Python-ideas] Re: Extract variable name from itself

2023-09-16 Thread Dom Grigonis
Agree, all good points. f'{=expr}'.split('.')[-1] Does take care of all cases and `nameof` has no additional use over it. It seems that `nameof` is out of question. DG > On 16 Sep 2023, at 19:50, Stephen J. Turnbull > wrote: > > Dom Grigonis writes: > >

[Python-ideas] Re: Extract variable name from itself

2023-09-16 Thread Dom Grigonis
If it is done at a tool level, it is not a robust solution. The fact that it can be done in a tool doesn’t mean that it is the optimal solution. Having it done at python level could be a simpler solution and provide benefits to all of the tools, without needing for editor logic to deviate from p

[Python-ideas] Re: Extract variable name from itself

2023-09-16 Thread Dom Grigonis
Yes, it seems it does have scope beyond editor in both cases. class A: a = 1 print(f'{=A.a}')# 'A.a' print(nameof(A.a)) # 'a' In f-string case, if to be consistent with current f-string functionality, expression would be checked for a validity and that reference is in scope and available.

[Python-ideas] Re: Extract variable name from itself

2023-09-15 Thread Dom Grigonis
So following this thread, from your perspective and from what has been said you can’t see or noticed any parts of it needing interpreter? DG > On 16 Sep 2023, at 03:14, Chris Angelico wrote: > > On Sat, 16 Sept 2023 at 10:07, Dom Grigonis wrote: >> >> >&g

[Python-ideas] Re: Extract variable name from itself

2023-09-15 Thread Dom Grigonis
> def nameof(x): return x > > print("This " + nameof("thing") + " is:", thing) Can you explain what you meant by this code? How would this work in editor? > > ChrisA > ___ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send a

[Python-ideas] Re: Extract variable name from itself

2023-09-15 Thread Dom Grigonis
Yes, I agree. This was exactly what I had in mind. Was good to find out that there is such implementation in other language. DG. > On 15 Sep 2023, at 17:00, Jeff Allen wrote: > > On 13/09/2023 17:21, MRAB wrote: >> I think the point is to have an equivalent to C#'s 'nameof'. >> >> It would b

[Python-ideas] Re: Extract variable name from itself

2023-09-14 Thread Dom Grigonis
Good ideas, however not robust: a = 1 b = 1 print(id(a))# 4536318072 print(id(b))# 4536318072 > On 14 Sep 2023, at 16:35, Jonathan Fine wrote: > > POSTSCRIPT > > We can also use locals() to 'inverse search' to get the name, much as in the > original post. > > >>> locals()['x'] > (0, 1

[Python-ideas] Re: Extract variable name from itself

2023-09-12 Thread Dom Grigonis
I agree. What I meant is that it is unreliable with `v is 710` and even more unreliable with `v == 710` as “==“ is less strict than “is”. DG > On 12 Sep 2023, at 21:03, Rob Cliffe wrote: > > >>> As for the example in your first post: >>> var = 710 >>> variable_name = [k for k, v in locals().

[Python-ideas] Re: Extract variable name from itself

2023-09-12 Thread Dom Grigonis
Good points, thanks for reply. > Or do you want to check that the expression can be evaluated at run time? > You could achieve that by simply writing > a.method Yes, the point is that it would be checked for legality of expression itself. Whether to check if it actually evaluates without an e

[Python-ideas] Re: Extract variable name from itself

2023-09-12 Thread Dom Grigonis
Yes, Thank you! So 2 solutions now. They both solve what I have encountered. Beyond that, they differ by: a) f-string print(f’{=a.method}’) # ‘a.method’ No new builtin needed. Simply reprints expression representation. b) print(nameof(a.method)) # ‘method’ New builti

[Python-ideas] Re: Extract variable name from itself

2023-09-12 Thread Dom Grigonis
e and not required. DG. > On 12 Sep 2023, at 13:06, Chris Angelico wrote: > > On Tue, 12 Sept 2023 at 20:05, Dom Grigonis wrote: >> >> Please read the next part of my e-mail too. It actually answer your question. >> > > I did re

[Python-ideas] Re: Extract variable name from itself

2023-09-12 Thread Dom Grigonis
Please read the next part of my e-mail too. It actually answer your question. > On 12 Sep 2023, at 13:00, Chris Angelico wrote: > > On Tue, 12 Sept 2023 at 19:51, Dom Grigonis wrote: >> >> It wouldn’t. I know this is weird and not in line of how things work. This &g

[Python-ideas] Re: Extract variable name from itself

2023-09-12 Thread Dom Grigonis
name, and why only one > name? > > Le mar. 12 sept. 2023 à 10:23, Dom Grigonis <mailto:dom.grigo...@gmail.com>> a écrit : > As far as I understand, it is not possible. Is it? > > Something similar to: > > var = 710 > variable_name = [k for k, v in loc

[Python-ideas] Extract variable name from itself

2023-09-12 Thread Dom Grigonis
As far as I understand, it is not possible. Is it? Something similar to: var = 710 variable_name = [k for k, v in locals().items() if v == 710][0] print("Your variable name is " + variable_name) ,except robust. Possible ways to expose it: * builtin function `varname(obj: object) —> str` * obje

[Python-ideas] Re: Revise using the colon ( : )

2023-09-11 Thread Dom Grigonis
xists. So this is incorrect. > Or: > while a < b(x := c) - 42: ># ??? Having that said, I think readability suffers a lot from not having a colon and as you indicated potentially makes parser’s job harder. Dg. > On 11 Sep 2023, at 20:11, Celelibi wrote: > > 2023-

[Python-ideas] Re: Have del return a value

2023-09-09 Thread Dom Grigonis
Also, check out https://docs.python.org/3/library/weakref.html Maybe it will not provide exactly what you indicated, but might get some ideas how to do things differently. — Now is better than never. Although never is often better than *right* no

[Python-ideas] Re: Revise using the colon ( : )

2023-09-05 Thread Dom Grigonis
I like the idea of eliminating it if it was possible. This is one of my most common syntax errors (although mostly after function signature) and I am not C/C++ programmer. I am not sure about the core technical issues, but readability of code, such as: a = 1 while a < 5: a += 1 , would suffer: a

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

2023-08-05 Thread Dom Grigonis
Ok. > On 5 Aug 2023, at 16:02, Chris Angelico wrote: > > On Sat, 5 Aug 2023 at 22:49, Dom Grigonis wrote: >> 9. Python has a syntax for conditional expressions. Learn it, if you want to >> use Python. No need to create multiple syntaxes for the same thing. >> *

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

2023-08-05 Thread Dom Grigonis
nswers I was looking for. Hopefully, this wasn’t a waste of time from your perspectives either. —Nothing ever dies, just enters the state of deferred evaluation— Dg > On 5 Aug 2023, at 09:22, Rob Cliffe wrote: > > When can we expect the results of your survey? (I responded to it

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

2023-07-24 Thread Dom Grigonis
common factor as similar problems have been bothering me too. To me by now, it is about custom user expressions. —Nothing ever dies, just enters the state of deferred evaluation— Dg > On 24 Jul 2023, at 18:17, Chris Angelico wrote: > > On Tue, 25 Jul 2023 at 01:03, Dom Grigonis wr

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

2023-07-24 Thread Dom Grigonis
> > Seriously, what is the obsession with putting things on one line here? > There is no obsession. It is more of a consideration of balance between operation complexity vs its verbosity. > If it's because "it works better when there is a long list of such > assignments" then unless you actual

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2023-07-23 Thread Dom Grigonis
one". Once you create this "special value", some function will decide to > make it have a meaning as a passed in value, and then need a DIFFERENT > "special value" as a default. > > On 7/23/23 1:13 AM, Dom Grigonis wrote: >> Or maybe you are not listenin

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2023-07-22 Thread Dom Grigonis
be, then at least to me, it would be a no-brainer to use it instead and to adapt it as best practice. DG > On 23 Jul 2023, at 07:35, Chris Angelico wrote: > > On Sun, 23 Jul 2023 at 14:08, Dom Grigonis wrote: >> >> IT IS AN OBJECT. Never said otherwise. > > One t

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2023-07-22 Thread Dom Grigonis
:58, Chris Angelico wrote: > > On Sun, 23 Jul 2023 at 12:20, Dom Grigonis wrote: >> >> >>> There is no way to have a value that isn't a value, in Python. The >>> concept doesn't make sense and would break all kinds of things. >>> (That'

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2023-07-22 Thread Dom Grigonis
> There is no way to have a value that isn't a value, in Python. The > concept doesn't make sense and would break all kinds of things. > (That's why, when a special function like __getitem__ has to be able > to return literally anything, it signals "nothing to return" by > raising an exception.)

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2023-07-22 Thread Dom Grigonis
1. Not if it is exactly as described in PEP. 2. No. 3. - 4. Couple of points here. One check and one orthogonal idea, which would make this PEP very attractive to me. I would definitely like use this functionality if both of below points were satisfied/achievable. If any of those weren't satisfi

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

2023-07-21 Thread Dom Grigonis
, this could be a nice one to have further along the lines, given def-eval was implemented. Then complete statements would be possible via expressions with full functionality. > On 21 Jul 2023, at 12:19, Chris Angelico wrote: > > On Fri, 21 Jul 2023 at 19:15, Dom Grigonis wrote: >&

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

2023-07-21 Thread Dom Grigonis
that I was looking at including reasonable route to achieve https://peps.python.org/pep-0463/ <https://peps.python.org/pep-0463/>. And it might be a feasible approach for deferred evaluation. Just not sure if this covers the needs that it is aiming to fulfil. DG > On 21 Jul 2023, at 10:31, Do

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

2023-07-21 Thread Dom Grigonis
t('Evaluating') return 1 a = `expr()` b = `a` # carry over lazy, but it's a new object at C level assert a is b # False assert !a is !b # True assert a is b # True > On 21 Jul 2023, at 08:46, Chris Angelico wrote: > > On Fri, 21 Jul 2023 at 1

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

2023-07-20 Thread Dom Grigonis
objects are provided, but can also be used with `normal` values. > On 20 Jul 2023, at 22:51, Random832 wrote: > > On Mon, Jul 17, 2023, at 16:41, Dom Grigonis wrote: >> Would be interesting to see if my preference is an outlier or not really. > > I think this is a false

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

2023-07-20 Thread Dom Grigonis
for your patience. > On 20 Jul 2023, at 12:38, Chris Angelico wrote: > > On Thu, 20 Jul 2023 at 19:34, Dom Grigonis wrote: >> And ideally, adding 2 builtin(or imported from stdlib) functions: `Break` >> and `Continue`, which if called act as `break` and `continue` sta

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

2023-07-20 Thread Dom Grigonis
I have looked more properly at deferred evaluation and late-bound defaults. Deferred-eval is overkill for what I need and isn’t likely to come about soon, while deferred only solves a very small part of what I am looking at. Also, it lacks ability to enforce default from outside, which is a bit

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

2023-07-20 Thread Dom Grigonis
that bar can be cached, so it will always be called twice. > > In Python then a better way might be > > result = temp := bar() if temp else default > > This way only bar() and default are evaluated and invoked once. > > > > -- Original Message --

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

2023-07-19 Thread Dom Grigonis
> result = bar or default I used to do this, but dropped this habit. Just to be on the safe side if in the future I extend bar to take value for which truth test evaluates to False. And for consistency across the codebase. ___ Python-ideas mailing

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

2023-07-19 Thread Dom Grigonis
> I think that's reasonable. But I don't think Python is the language > for that. There are too much existing contrasts, such as loop vs. > comprehension and conditional statement vs. ternary expression. Guido > deliberately chose to vary those expression syntaxes from their > statement equival

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

2023-07-19 Thread Dom Grigonis
who want/need to write very logically consistent, optimised and concise code. Thank you for reply, DG > On 19 Jul 2023, at 09:25, Stephen J. Turnbull > wrote: > > Dom Grigonis writes: > >>> But "encourages one-liners" is generally considered an >>

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

2023-07-18 Thread Dom Grigonis
romising... > On 18 Jul 2023, at 09:45, Chris Angelico wrote: > > On Tue, 18 Jul 2023 at 16:25, Dom Grigonis wrote: >> >> Yes, thank you, this would definitely be nice to have. >> >> Although, "A generic system for deferred evaluation has been proposed at

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

2023-07-18 Thread Dom Grigonis
18 Jul 2023, at 23:59, Chris Angelico wrote: > > 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 co

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

2023-07-18 Thread Dom Grigonis
ness = y/x Conciseness = x/y Thus, expressiveness = 1 / conciseness. Maybe I am not using the terminology correctly (seems right to me, given etymology of these words), but this is just to explain what I meant. > On 18 Jul 2023, at 18:34, Paul Moore wrote: > > On Tue, 18 Jul 2023 at

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

2023-07-18 Thread Dom Grigonis
18 Jul 2023, at 18:11, Dom Grigonis wrote: > > 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, eve

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

2023-07-18 Thread Dom Grigonis
023, at 17:57, Chris Angelico wrote: > > 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

[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
omeone else's. > On 18 Jul 2023, at 16:38, Stephen J. Turnbull > wrote: > > 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

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

2023-07-18 Thread Dom Grigonis
18 Jul 2023, at 09:45, Chris Angelico wrote: > > On Tue, 18 Jul 2023 at 16:25, Dom Grigonis wrote: >> >> Yes, thank you, this would definitely be nice to have. >> >> Although, "A generic system for deferred evaluation has been proposed at >> times“ s

[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-17 Thread Dom Grigonis
Angelico wrote: > > On Tue, 18 Jul 2023 at 14:07, Dom Grigonis wrote: >> PEP505 would solve this nicely, but it only applies to None and would not >> apply to say user-defined sentinels and many other cases where permutations >> of different conditionals arise. >> &g

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

2023-07-17 Thread Dom Grigonis
information. > On 18 Jul 2023, at 04:40, Greg Ewing wrote: > > On 18/07/23 10:30 am, Dom Grigonis wrote: >> Although, the argument that python is meant to be read as english is very >> much valid, but I do not see why it has to be an overarching one if the >> opportun

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

2023-07-17 Thread Dom Grigonis
Much of what you respond to me indicates that you did not properly read what I have written and did not really understand where I am coming from. > On 18 Jul 2023, at 04:04, Chris Angelico wrote: > > On Tue, 18 Jul 2023 at 10:37, Dom Grigonis wrote: >> As opposed to >> &

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

2023-07-17 Thread Dom Grigonis
interpreted language written in another language, I really FAIL to see how is all of this NOT about conciseness and modularity? I agree that there are other dimensions, but I always thought python being closer to unix than windows... > On 18 Jul 2023, at 03:08, Chris Angelico wrote: >

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

2023-07-17 Thread Dom Grigonis
On Tue, 18 Jul 2023 at 04:37, Dom Grigonis <mailto:dom.grigo...@gmail.com>> wrote: > > This is why, I would dare to say that this preference of mine is not > > affected by prejudices. > > Of course it's affected by prejudices -- all our preferences are. A sample

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

2023-07-17 Thread Dom Grigonis
easily digestible. > On 17 Jul 2023, at 21:37, Dom Grigonis wrote: > > This is NOT a good example, my first language was R, second - python, third > matlab, etc. > > I only became familiar with C/C++ after several years of coding experience. > > This is why, I wou

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

2023-07-17 Thread Dom Grigonis
and other 1-liners were close to half of all examples. > On 18 Jul 2023, at 00:04, Chris Angelico wrote: > > On Tue, 18 Jul 2023 at 06:40, Dom Grigonis wrote: >> >> We even got a new operator “:=“ to help us with those beautiful one-liners >> (or not) to move towards

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

2023-07-17 Thread Dom Grigonis
det wrote: > > Hello all, > > Please Dom Grigonis add choices : > - "No preference" choice to first question > - "I don't know" or "I can't tell" to third question > And I will answer to your poll and probably other people will feel an

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

2023-07-17 Thread Dom Grigonis
hink the Python version does the right thing by emphasizing the DEFAULT by > putting it first, and leaving the predicate and fallback until later in the > expression (right for Pythonic code, not right for other languages > necessarily). > > Either way, the question is mo

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

2023-07-17 Thread Dom Grigonis
2023, at 23:57, Chris Angelico wrote: > > On Tue, 18 Jul 2023 at 04:37, Dom Grigonis wrote: >> >> This is NOT a good example, my first language was R, second - python, third >> matlab, etc. >> >> I only became familiar with C/C++ after several years of coding e

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

2023-07-17 Thread Dom Grigonis
Hi everyone, I am not very keen on long discussions on such matter as I do not think there is much to discuss: there is no technical complexity in it and it doesn’t really change or introduce anything new. It is only a matter of opinion & style/design preferences with respect to logical order a

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

2023-07-17 Thread Dom Grigonis
do not have a bias towards C or C++, 99% of what I do is python so if anything I am biased towards how python does things, not the other way round. Is there any place > On 17 Jul 2023, at 23:09, Ned Batchelder wrote: > > On 7/17/23 1:10 PM, Dom Grigonis wrote: >> This whole

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

2023-07-17 Thread Dom Grigonis
ris Angelico wrote: > > On Tue, 18 Jul 2023 at 03:13, Dom Grigonis wrote: >> Maybe for someone who majored in languages python’s if-else is more easily >> understood. To me, personally, 2nd one is unbearable, while 1st one is >> fairly pleasant and satisfying. >> &

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

2023-07-17 Thread Dom Grigonis
: > > > > On 15/07/2023 21:08, Dom Grigonis wrote: >> Just to add. I haven’t thought about evaluation. Thus, to prevent evaluation >> of unnecessary code, introduction of C-style expression is needed anyways: >>> 1. result = bar is None ? default : bar >&

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

2023-07-15 Thread Dom Grigonis
conditional expression existed, it would significantly change the way I write things. So just checking. :) > On 16 Jul 2023, at 00:06, Paul Moore wrote: > > On Sat, 15 Jul 2023 at 21:09, Dom Grigonis <mailto:dom.grigo...@gmail.com>> wrote: > So I would vote for something simila

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

2023-07-15 Thread Dom Grigonis
15 Jul 2023, at 22:37, Dom Grigonis wrote: > > def fu(bar, default=1): > bar = bar or default > return bar > > print(fu(None)) # 1 - as expected > print(fu(2)) # 2 - as expected > print(fu(0)) # 1 - not as expected > > class A: >

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

2023-07-15 Thread Dom Grigonis
t’s face value) is too limiting, and potentially too invasive for too little benefit in relation to how close to `python’s metal` it is. > On 15 Jul 2023, at 20:57, Jothir Adithyan wrote: > > Dom Grigonis wrote: >> This feels superfluous. Instead of creating new dict class I w

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

2023-07-15 Thread Dom Grigonis
. > On 15 Jul 2023, at 21:07, Jothir Adithyan wrote: > > Dom Grigonis wrote: >> 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,

[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: > > This

[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: "Curated" package repo?

2023-07-06 Thread Dom Grigonis
hon with conventions? > Whatever it is, it should have a gentle learning curve and be human readable > IMO. > > > > On Thu, Jul 6, 2023 at 9:26 AM Dom Grigonis <mailto:dom.grigo...@gmail.com>> wrote: > It is possible, that issues being discussed at this stage

[Python-ideas] Re: "Curated" package repo?

2023-07-06 Thread Dom Grigonis
It is possible, that issues being discussed at this stage are not as relevant as they seem at stage 0, which this idea is at. (Unless someone here is looking for a very serious commitment.) If some sort of starting point which is “light” in approach was decided on, then the process can be readju

[Python-ideas] Re: "Curated" package repo?

2023-07-05 Thread Dom Grigonis
One way would be to categorise areas and sub-areas and have a clear indication, where the work has not been done. So that if I came to such place, I could find the sub-topic that I am interested in with clear indication of the status. > On 5 Jul 2023, at 21:48, Brendan Barnwell wrote: > > On

[Python-ideas] Re: Double "at" operator for matmul exponentiation

2023-07-05 Thread Dom Grigonis
> On 5 Jul 2023, at 21:07, Chris Angelico wrote: > > On Thu, 6 Jul 2023 at 04:02, Dom Grigonis wrote: >> What I would alternatively propose is to introduce a couple of (meaningless >> operators), so that library developers can make use of them as they wish. >>

  1   2   >