Re: Extract variable name from itself

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.
why is it a bad idea to have: c) `expr` without `repr(expr)`? This does cover `identifier only` case as well, but is not limited to it. Is it difficult to achieve? Apologies if I am missing something, but if you know the workings of python, could you point me to where f’{expr=}' is parsed and compiled? Obviously I might be wrong, but it is difficult to believe that it is done in such way, that I can have B, A&B, but not A without B. Would appreciate if you convinced me with some support for your rather strong statements. Regards, DG

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/67977672360659f203664d2... <https://github.com/python/cpython/pull/13123/commits/67977672360659f203664d2...> 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

A little late, but the requirement to "Extract variable name from itself" is widely used in Django. Each field in a Django model, knows it's own variable name user_name = models.CharField(...) The instance of CharField knows that it's variable name is "user_name", so that it can name the row in the database the same. On startup Django runs through the Model class searching for instances of Field and gets the name that way

That is true, but of course in Django the field is an object, and it is the object that knows it's name. There is nothing to stop you declaring a field in a model called 'person_name' but also doing this in the code : user_name = instance.person_name In Django the user_name variable will only have the name 'person_name', but not user_name, as the field objects need to know their names on the model (and their names on the views/forms). ------ Original Message ------ From: "Rene Nejsum" <rene@pylots.com> To: python-ideas@python.org Sent: Saturday, 4 Nov, 23 At 08:13 Subject: [Python-ideas] Re: Extract variable name from itself A little late, but the requirement to "Extract variable name from itself" is widely used in Django. Each field in a Django model, knows it's own variable name user_name = models.CharField(...) The instance of CharField knows that it's variable name is "user_name", so that it can name the row in the database the same. On startup Django runs through the Model class searching for instances of Field and gets the name that way _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/SJUKWX... Code of Conduct: http://python.org/psf/codeofconduct/ -- <br>Anthony Flury<br>anthony.flury@btinternet.com

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/67977672360659f203664d2... <https://github.com/python/cpython/pull/13123/commits/67977672360659f203664d2...> 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

A little late, but the requirement to "Extract variable name from itself" is widely used in Django. Each field in a Django model, knows it's own variable name user_name = models.CharField(...) The instance of CharField knows that it's variable name is "user_name", so that it can name the row in the database the same. On startup Django runs through the Model class searching for instances of Field and gets the name that way

That is true, but of course in Django the field is an object, and it is the object that knows it's name. There is nothing to stop you declaring a field in a model called 'person_name' but also doing this in the code : user_name = instance.person_name In Django the user_name variable will only have the name 'person_name', but not user_name, as the field objects need to know their names on the model (and their names on the views/forms). ------ Original Message ------ From: "Rene Nejsum" <rene@pylots.com> To: python-ideas@python.org Sent: Saturday, 4 Nov, 23 At 08:13 Subject: [Python-ideas] Re: Extract variable name from itself A little late, but the requirement to "Extract variable name from itself" is widely used in Django. Each field in a Django model, knows it's own variable name user_name = models.CharField(...) The instance of CharField knows that it's variable name is "user_name", so that it can name the row in the database the same. On startup Django runs through the Model class searching for instances of Field and gets the name that way _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/SJUKWX... Code of Conduct: http://python.org/psf/codeofconduct/ -- <br>Anthony Flury<br>anthony.flury@btinternet.com
participants (3)
-
anthony.flury
-
Dom Grigonis
-
Rene Nejsum