This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients Gabriele Tornetta, bup, r.david.murray, steven.daprano
Date 2021-12-09.15:34:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <20211209153221.GP21647@ando.pearwood.info>
In-reply-to <1639062157.18.0.257697415684.issue32683@roundup.psfhosted.org>
Content
If you don't want to customise attribute access, don't overload 
`__getattribute__`. The documentation for `__getattribute__` is clear 
about what it does:

"Called unconditionally to implement attribute accesses for instances of 
the class."

https://docs.python.org/3/reference/datamodel.html#object.__getattribute__

That includes lookups for `__class__`, regardless of whether the 
function doing the lookup is isinstance or some other function.

You ask:

"Are there any reasons why __class__ cannot be retrieved with
object.__getattribute__ instead?"

Yes, that would ignore overloaded attribute access, which would be a 
bug in my opinion.

Being able to dynamically generate computed attributes by overloading 
`__getattr__` and `__getattribute__` is not a bug. It is part of 
Python's data model. See the documentation above.

And that includes `__class__`.

I don't believe that it is an accident or a bug that isinstance uses 
ordinary attribute lookup, which goes through the standard mechanism 
including the class' own `__getattribute__` method. But I will ask on 
the Python-Dev mailing list in case Guido or other core developers think 
that it is wrong to do so.
History
Date User Action Args
2021-12-09 15:34:56steven.dapranosetrecipients: + steven.daprano, r.david.murray, bup, Gabriele Tornetta
2021-12-09 15:34:56steven.dapranolinkissue32683 messages
2021-12-09 15:34:56steven.dapranocreate