[Python-ideas] Re: Extract variable name from itself
On Sat, 16 Sept 2023 at 10:20, Dom Grigonis wrote: > > 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? Correct. Trying to get a variable name from an object is nonsensical, and trying to get a variable name from a text string is simply "return the text string unchanged". ChrisA ___ 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-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/5DGG4NECPJ4UNCNTRNBE2OM7F2JGCGT3/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Extract variable name from itself
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: >> >> >>> 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? >> > > Frankly, I have no idea, because your **entire proposal** is > predicated on some sort of automated tool for renaming variables. > Without knowing the details of that tool, how can I tell you how this > would work? > > But if that tool can be taught that nameof indicates a variable name, > then it can rename inside it just like it would rename anything else. > > Your problem here is a limitation of the variable renaming tool. I'm > suggesting a solution to that problem. This is not a language problem, > it's an editor problem, so it needs an editor solution. > > ChrisA > ___ > 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-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/I6KUD7LCGYV4JES77A7PZDVBHWVIKXF3/ > Code of Conduct: http://python.org/psf/codeofconduct/ ___ 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-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/IDOWZCWN6CPEVFOUZGDPRKD7QV36ZCHL/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Extract variable name from itself
On Sat, 16 Sept 2023 at 10:07, Dom Grigonis wrote: > > > > 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? > Frankly, I have no idea, because your **entire proposal** is predicated on some sort of automated tool for renaming variables. Without knowing the details of that tool, how can I tell you how this would work? But if that tool can be taught that nameof indicates a variable name, then it can rename inside it just like it would rename anything else. Your problem here is a limitation of the variable renaming tool. I'm suggesting a solution to that problem. This is not a language problem, it's an editor problem, so it needs an editor solution. ChrisA ___ 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-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/I6KUD7LCGYV4JES77A7PZDVBHWVIKXF3/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Extract variable name from itself
> 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 an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/MRHSRDWF3IR6ZEC7HFE5VBPS2YW4CITX/ > Code of Conduct: http://python.org/psf/codeofconduct/ ___ 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-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/7Y2AOC6ATEOCMIZNNJERSDUKF2L5DCVD/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Extract variable name from itself
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 be evaluated at compile time to a string, but with the advantage >> that it's clear that it's a name and not some random string that just >> happens to look like a name. >> > I'd like to draw attention to this as the first contribution to the thread > that has given a precise meaning to the initial idea. It tells us both what > it means and why you might want it (at least if the OP agrees). It seems to > be being overlooked. > > As others have amply demonstrated (short of proof, I know) what is being > asked is not possible with the information available at run-time. You can't > reliable get from the "reference", which is actually an expression, to the > text of the expression. > > The parallel with f-string = is helpful, for which compile-time support is > essential, of course. > > -- > > Jeff Allen > ___ > 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-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/45P4HD5LBNDCPUGRRWWDV6XGR6H3GCDB/ > Code of Conduct: http://python.org/psf/codeofconduct/ ___ 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-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/X6GLLYE3VAGCLCCWGQNGXJTISI2WMTXY/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Extract variable name from itself
On Sat, 16 Sept 2023 at 08:50, Jeff Allen wrote: > The parallel with f-string = is helpful, for which compile-time support is > essential, of course. 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 feature at all. It's an editor refactoring feature. ChrisA ___ 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-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MRHSRDWF3IR6ZEC7HFE5VBPS2YW4CITX/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Extract variable name from itself
On 13/09/2023 17:21, MRAB wrote: I think the point is to have an equivalent to C#'s 'nameof'. It would be evaluated at compile time to a string, but with the advantage that it's clear that it's a name and not some random string that just happens to look like a name. I'd like to draw attention to this as the first contribution to the thread that has given a precise meaning to the initial idea. It tells us both what it means and why you might want it (at least if the OP agrees). It seems to be being overlooked. As others have amply demonstrated (short of proof, I know) what is being asked is not possible with the information available at run-time. You can't reliable get from the "reference", which is actually an expression, to the text of the expression. The parallel with f-string = is helpful, for which compile-time support is essential, of course. -- Jeff Allen ___ 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-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/45P4HD5LBNDCPUGRRWWDV6XGR6H3GCDB/ Code of Conduct: http://python.org/psf/codeofconduct/