[pypy-issue] Issue #2096: isinstance(obj, cls) should not call __instancecheck__ if type(obj)==cls (pypy/pypy)
kmod
issues-reply at bitbucket.org
Wed Jul 22 23:39:49 CEST 2015
New issue 2096: isinstance(obj, cls) should not call __instancecheck__ if type(obj)==cls
https://bitbucket.org/pypy/pypy/issues/2096/isinstance-obj-cls-should-not-call
kmod:
CPython fast-paths this case to always return true. Seems like probably user error if instancecheck returns false for instances of that type :P but it's still a difference:
```
class M(type):
def __instancecheck__(self, obj):
print "instancecheck", type(obj)
return False
class C(object):
__metaclass__ = M
class D(C):
pass
d = D()
print isinstance(d, C) # should call instancecheck
print isinstance(d, D) # should not call instancecheck
```
In the second isinstance(), CPython (2.7.6) doesn't call instancecheck, but PyPy (2.6.0) does.
More information about the pypy-issue
mailing list