On 1/31/20 9:28 PM, Christopher Barker wrote:
I am really confused by this whole thread:
(I know this has all been said in this thread, but I’m summarizing to
get us on the same page for the following comments)
Python has names, and it has values (objects, whatever) when we write
Python, we bind names to values with the = operator. (And other
namespace trickery). Some types of objects do have a __name__
attribute: classes, functions created with def.
But that name is only sometimes the same as the name(s) it might be
bound to in any given namespace. So what the heck is nameof() supposed
to mean? A few examples:
>>> x = 5
>>>nameof(x)
OK, I suppose that’s “x” — but what is the point of that? You have to
know the name already.
What about:
y = 5
x = 5
(Or x = y)
What is nameof(x) And nameof(y)?
What about nameof(5)?
Now:
def fun():
pass
I suppose nameof(fun) is “fun”, but again, is that useful?
And now:
Fred = fun
What’s nameof(Fred)
If it’s “Fred” then again, useless.
If it’s “fun” then what about x and y before?
And:
def fun():
y = something
return y
lst.append(fun())
nameof(lst[-1])
????
In short, if it means “what is the name of this name” that seems
completely useless?
If it means: what name is this object bound to in this namespace? Than
I can see how one might think that would be useful, but the answer
could be:
No name at all
More than one name
A name different than the object’s __name__
And then there is the question of the local vs global namespace, the
list goes on.
This thread has been going on a while:
What am I missing?
-CHB
My understanding is that the impetus of the request is that if you start
from an expression like nameof(foo.bar) to get to "bar" then if you
refactor your code you have a chance that the tool will be able to see
the variable expression foo.bar, and process that like other references
to the item, and thus be able to change it. Just using the string "bar"
would be very hard to see the connection between foo.bar and "bar".
--
Richard Damon
_______________________________________________
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/SLUI4AHPPDS3FB35SZ5EL6QX4ZIA4HDB/
Code of Conduct: http://python.org/psf/codeofconduct/