I understand that __dict__
in obj.__dict__
is a descriptor attribute of type(obj)
, so the lookup for obj.__dict__
is type(obj).__dict__['__dict__'].__get__(obj)
.
From https://stackoverflow.com/a/46576009
It's tempting to say that
__dict__
has to be a descriptor because implementing it as a__dict__
entry would require you to find the__dict__
before you can find the__dict__
, but Python already bypasses normal attribute lookup to find__dict__
when looking up other attributes, so that's not quite as compelling as it initially sounds. If the descriptors were replaced with a'__dict__'
key in every__dict__
,__dict__
would still be findable.
How does "Python already bypasses normal attribute lookup to find __dict__
"? What does "normal attribute lookup" mean?
According to the context of the quote in the link, I don't think when the author wrote that, he referred to that the lookup for obj.__dict__
is type(obj).__dict__['__dict__'].__get__(obj)
.