[docs] [issue25432] isinstance documentation doesn't explain what happens when type is tuple

eryksun report at bugs.python.org
Sat Oct 17 13:25:21 EDT 2015


eryksun added the comment:

Since Python has multiple inheritance, it could be misconstrued as a conjunctive test. For example, if c is an instance of C, which subclasses both A and B, then someone might think isinstance(c, (A, B)) requires c to be an instance of both A and B. The description could clarify that it's a disjunctive test with short circuiting.

    class MetaA(type):
        def __instancecheck__(self, other):
            print('MetaA.__instancecheck__')
            return False

    class A(metaclass=MetaA): pass

    >>> isinstance(1, (A, int))
    MetaA.__instancecheck__
    True
    >>> isinstance(1, (int, A))
    True

----------
keywords: +easy
nosy: +eryksun

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25432>
_______________________________________


More information about the docs mailing list