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 bup
Recipients bup
Date 2018-01-26.21:10:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1517001040.56.0.467229070634.issue32683@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2018-01-26 21:10:40bupsetrecipients: + bup
2018-01-26 21:10:40bupsetmessageid: <1517001040.56.0.467229070634.issue32683@psf.upfronthosting.co.za>
2018-01-26 21:10:40buplinkissue32683 messages
2018-01-26 21:10:40bupcreate