[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 mean '=' here? That is, you want to > a

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

2023-09-23 Thread Pyrous
>It's really something that needs editor support, not compiler support. As far as the Python interpreter is concerned, this is just a string.>So why not just make it an editor feature?>def nameof(x): return x>print("This " + nameof("thing") + " is:", thing)>As far as I can tell, this isn't a Python

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

2023-09-23 Thread Tiago Illipronti Girardi
This is the only use case I can think of. It could be supported by the typing module by subtyping LiteralString and let the editor tools do the rest. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le

[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 Tiago Illipronti Girardi
but: 1. There are costs doing it in python. And easy implementation doing it in editor (with the typing support it's almost already done). 2. The f-string functionality is not there right now, but f'{name!id}' would leverage what is there and, with editor support, give the exact `nameof`` support e

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

2023-09-23 Thread Dom Grigonis
> On 23 Sep 2023, at 16:24, Tiago Illipronti Girardi > wrote: > > but: > 1. There are costs doing it in python. And easy implementation doing it in > editor (with the typing support it's almost already done). What are those costs? > 2. The f-string functionality is not there right now, but f'

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

2023-09-23 Thread Dom Grigonis
> the output will have the expression text This is exactly what I want. If there was an extra check for validity at parser level, it is a plus. > You want to produce a name, that is an identifier > . Not necessarily, I want

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

2023-09-23 Thread Dom Grigonis
It seems that my guess was correct. There was a commit, when only the first part was working: https://github.com/python/cpython/pull/13123/commits/67977672360659f203664d23cfc52b5e07e4381a So it does

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

2023-09-23 Thread Dom Grigonis
> Since I wrote that commit: no one is saying it’s impossible or overly > difficult, To be honest it is exactly what was being said. > just that the benefit of having it doesn’t justify the cost of adding it. I can understand that. > I understand that you think it’s worth the cost. No, I don’t

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

2023-09-23 Thread Eric V. Smith via Python-ideas
On Sep 23, 2023, at 5:37 PM, Dom Grigonis wrote:It seems that my guess was correct. There was a commit, when only the first part was working:https://github.com/python/cpython/pull/13123/commits/67977672360659f203664d23cfc52b5e07e4381aSince I wrote that commit: no one is saying it’s impossible or

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

2023-09-23 Thread Stephen J. Turnbull
Dom Grigonis writes: > Eric Smith wrote: >> Since I wrote that commit: no one is saying it’s impossible or >> overly difficult, > To be honest it is exactly what was being said. Sure ... about an unclearly expressed early version of the proposal, that seemed to ask "given an object x, te

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

2023-09-23 Thread Dom Grigonis
I haven’t given much thought regarding the syntax. The prefix “=“ just popped into my mind and I went along with it to use in my examples. The point was that f-strings are potentially a good place to implement such thing. By “elegant", I wasn’t talking about the syntax. It was more about the ben