Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32683> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com