> On 9 Dec 2021, at 16:41, Steven D'Aprano <st...@pearwood.info> wrote: > > I'm looking for some guidance on a bug report involving isinstance and > __getattribute__` please. > > The issue is that if your class overloads `__getattribute__`, calling > isinstance on an instance will call the overloaded `__getattribute__` > method when looking up `__class__`, potentially causing isinstance to > fail, or return the wrong result. > > See b.p.o. #32683 > > https://bugs.python.org/issue32683 > > I see no reason why this isn't working as designed, __getattribute__ is > intended to overload attribute access, and that could include the > `__class__` attribute. Am I wrong? > > It has been suggested that isinstance should call `object.__getattribute__` > and bypass the class' overloaded method, but I expect that would > probably break objects which intentionally lie about their class. > (Mocks? Stubs? Proxies?)
https://mail.python.org/pipermail/python-dev/2015-October/141953.html <https://mail.python.org/pipermail/python-dev/2015-October/141953.html> is an old thread about the difference between type(x)/Py_TYPE(x) and x.__class__ that contains some insight about this. Proxy types are one use case, although with some sharp edges. Ronald — Twitter / micro.blog: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/UTFAVD5CW6DWESWXEBIIF2RHSKO6FVCC/ Code of Conduct: http://python.org/psf/codeofconduct/