[Python-ideas] Explicit encapsulation is better than implicit hardcoding?

2023-06-08 Thread Dom Grigonis
Hey there! I'm curious to know what this group thinks about the implicit design of many Python libraries, both core and open source. What I mean by "implicit design" is when an interface of library is established and initialised at module’s level rather than explicitly encapsulated in classes.

[Python-ideas] Undefined type

2023-06-08 Thread Dom Grigonis
This has been bugging me for a long time. It seems that python doesn’t have a convention for “Undefined” type. When I started using python I naturally used None for it (as advised). However, the more I work with python, the more I find that None is a meaningful type. And it is a type that is co

[Python-ideas] Fwd: Undefined type

2023-06-08 Thread Dom Grigonis
Thank you all for links. Much appreciated. > Begin forwarded message: > > From: Michael Foord > Subject: Re: [Python-ideas] Re: Undefined type > Date: 8 June 2023 at 17:41:46 EEST > To: [email protected] > Cc: Dom Grigonis , [email protected] > > The

[Python-ideas] Fwd: Explicit encapsulation is better than implicit hardcoding?

2023-06-08 Thread Dom Grigonis
gin forwarded message: > > From: "Joao S. O. Bueno" > Subject: Re: [Python-ideas] Explicit encapsulation is better than implicit > hardcoding? > Date: 8 June 2023 at 20:36:11 EEST > To: Dom Grigonis > Cc: [email protected] > > "it's a bit more ch

[Python-ideas] yield functionality to match that of await

2023-06-12 Thread Dom Grigonis
I was wandering if there are any issues in making `yield` usage to be the same as that of `await` Most importantly: l.append(yield Object()) Nice to have: yield with Object(): yield for i in Object(): Also, could anyone point me in the direction, where it is explained why new await/async synta

[Python-ideas] Re: Undefined type

2023-06-12 Thread Dom Grigonis
as you do, seems like a good solution. It > means *you* control what meaning it has in the contexts where it appears. > Best wishes > Rob Cliffe > > On 07/06/2023 17:43, Dom Grigonis wrote: >> This has been bugging me for a long time. It seems that python doesn’t have &

[Python-ideas] Re: Warn when iterating over an already exhausted generator

2023-06-13 Thread Dom Grigonis
In close to 10 years of experience with python I have never encountered anything like this. If I need to use a list later I never do ANY assignments to it. Why would I? In the last example I would: ``` strings = ['aa', '', 'bbb', 'c’] longest = max(filter(bool, strings), key=len) n_unique = len(

[Python-ideas] Re: Warn when iterating over an already exhausted generator

2023-06-13 Thread Dom Grigonis
oper, in this short example, with all the parts introduced together, > yes. But having a natural solution silently give wrong answers is dangerous. > At least having a warning would break the false sense of security. > > I understand that backwards compatibility will probably pre

[Python-ideas] List get/pop

2023-06-14 Thread Dom Grigonis
Very simple proposal. E.g. ``` >>> l = [‘a’, ‘b’] >>> l.get(0) ‘a’ >>> l.get(2) None >>> l.pop(1, default=‘c’) ‘b’ >>> l.pop(1, default=‘c’) ‘c' ``` Essentially to match them to those of a dict. Current workarounds: ``` try: a = b[n] except IndexError: a = default # and l[index] if -len(l

[Python-ideas] Re: List get/pop

2023-06-14 Thread Dom Grigonis
at 23:11, Chris Angelico wrote: > > On Thu, 15 Jun 2023 at 06:04, Dom Grigonis wrote: >> So following Chris’ logic... >> If there are 10,000,000 python users on Stack… >> And we assume, that every user encounters such need at least 2 times a year >> (being

[Python-ideas] Re: List get/pop

2023-06-16 Thread Dom Grigonis
Just to add. I think same methods would be useful to have for strings as well. > On 14 Jun 2023, at 23:28, Dom Grigonis wrote: > > Yes, > 1. adding keyword argument for `pop` > 2. implementing `get` method as it doesn’t exist at all > * This wouldn’t break anyth

[Python-ideas] Re: dict method to retrieve a key from a value

2023-06-30 Thread Dom Grigonis
In my experience, the implementation of bijective dict is largely application specific. 1. Unique-valued dict is fairly straight forward and there is little ambiguity on implementation using 2 dicts. 2. However, if values are not to be unique, then it largely depends on application. (best (as i

[Python-ideas] Re: dict method to retrieve a key from a value

2023-07-01 Thread Dom Grigonis
Another idea, maybe this group could host a simple git repo. If idea of extension is reasonable, but it’s not for standard library, open source is not reliable or it's time for consensus and centralisation. Then people can make some PRs, see where it goes. In this case, OP could scan PyPI, make

[Python-ideas] Re: dict method to retrieve a key from a value

2023-07-01 Thread Dom Grigonis
they lacking? 2. What potential 3rd party solutions have you found and how were they lacking? What’s the worst that can happen? > On 1 Jul 2023, at 15:34, Chris Angelico wrote: > > On Sat, 1 Jul 2023 at 22:32, Dom Grigonis wrote: >> >> Another idea, maybe this group cou

[Python-ideas] Re: dict method to retrieve a key from a value

2023-07-01 Thread Dom Grigonis
> >> What’s the worst that can happen? >> > > The less centralized it is, the less bad things can happen. True, but the risk can be minimised if only appropriate cases were streamlined. Only well researched, well defined, unambiguous problems, that depend on mature components of core python

[Python-ideas] Re: dict method to retrieve a key from a value

2023-07-02 Thread Dom Grigonis
Some automation could be done for adding new packages to already existing PRs, where correct addition would integrate nicely, align stats, such as last update, stack trends, benchmarks > On 2 Jul 2023, at 09:36, Christopher Barker wrote: > > On Sat, Jul 1, 2023 at 11:01 PM Chris Angelico

[Python-ideas] Re: dict method to retrieve a key from a value

2023-07-04 Thread Dom Grigonis
> On 2 Jul 2023, at 10:12, Paul Moore wrote: > > On Sun, 2 Jul 2023 at 06:11, Christopher Barker > wrote: > > The OP of this thread is not alone -- folks want an authoritative source > ... > Unfortunately, too much of this discussion is framed as “someone should”, o

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

2023-07-04 Thread Dom Grigonis
To have 4) would be great. 2) could be a temporary test pilot to get some ideas when/if 4) was to be implemented. Starting point for 2) could be simple (?). E.g. 4 parts: 1. Features & integration 2. Performance - set-up automatic benchmarking via CI 3. Status (stack hits, user base, open i

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

2023-07-05 Thread Dom Grigonis
From perspective of calculation time of matrix multiplications Infix operators is a reasonable solution to define a subset of your own. https://doc.sagemath.org/html/en/reference/misc/sage/misc/decorators.html#sage.misc.decorators.infix_operator The problem is that if one implements it, there ha

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

[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: "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-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:[email protected]>> wrote: > It is possible, that issues being discussed at this stage

[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 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-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-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
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
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:[email protected]>> wrote: > So I would vote for something simila

[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-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
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] 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
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] 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: 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: 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: 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
On Tue, 18 Jul 2023 at 04:37, Dom Grigonis <mailto:[email protected]>> 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: 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: 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
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
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

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
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: 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: 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
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
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
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 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: 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-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: 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
> 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-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-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
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: 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: 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-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
, 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: 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: 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
: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
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-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: 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: 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: 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: 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: 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: 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-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] 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: 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:[email protected]>> 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] 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
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
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
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
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-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-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-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 -- [email protected] > To unsubscribe send a

[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-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-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
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
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-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-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: 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-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: 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-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
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:[email protected]>> 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
> 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
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
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
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: >

  1   2   >