New submission from Dan Snider <mr.assume.a...@gmail.com>:

It doesn't even care if the result it gets from 
ob.__getattribute__("__class__") isn't a type.

Surely `isinstance` is intended to do what it is named and be guaranteed to 
return True if an object `ob` is an instance of class `cls`. There are already 
ways to trick `isinstance` into thinking objects are instances of types not 
present in its __mro__, ie with abstract base classes. All this does is 
introduce the possibility of bugs.

`inspect.isclass` in particular is affected. If there's some obscure use case 
for breaking `isinstance` in this manner, surely it shouldn't apply to 
`inspect.isclass` which according to its documentation, "Return true if the 
object is a class."

from inspect import isclass
class Liar:
    def __getattribute__(self, attr):
        if attr == '__class__':
            return type
        return object.__getattribute__(self, attr)

>>> islcass(Liar())
True

----------
components: Interpreter Core, Library (Lib)
messages: 310793
nosy: bup
priority: normal
severity: normal
status: open
title: isinstance is calling ob.__getattribute__ as a fallback instead of 
object.__class__.__get__
versions: Python 3.7

_______________________________________
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

Reply via email to