Take the following code:
class MyMeta(type):
def __instancecheck__(cls, instance):
print('Checking instance')
return True
class MyClass(object):
__metaclass__ = MyMeta
print(isinstance(1, MyClass))
In Python 2.7, the output is
checking instance
True
In Python 3.5, the output is
False
This implies the __instancecheck__
of MyMeta
is being used in Python 2 but not in Python 3 for whatever reason. The section on __isinstance__
is the same in the Python 2 and 3 docs, and I haven't been able to find the cause of this difference of behavior. Anyone know why?