My stupidity / strange inconsistency overriding class methods
andrew at acooke.org
Wed Apr 20 01:52:57 CEST 2011
I've been staring at this problem, in various forms, all day. Am I missing something obvious, or is there some strange hardwiring of isinstance? This is with Python 3.2.
def __instancecheck__(cls, instance): return False
# no override
assert isinstance(A(), A)
assert A.__class__.__instancecheck__(A, A())
def foo(self): return 42
def foo(cls): return 7
assert C().__class__.foo() == 7
It seems to me that the above two cases are inconsistent. ABCMeta declares __instancecheck__ just like B declares foo. Yet C can override foo, but A is unable to override the instance check.
More information about the Python-list