Actually the problem is related to __new__ , not __init__ . Example:
from abc import ABCMeta, abstractmethod from collections import OrderedDict class Foo(metaclass=ABCMeta): @abstractmethod def foo(self): return 42 class Empty: def __init__(self): pass class C1(Empty, Foo): pass class C2(OrderedDict, Foo): pass
C1() does not work with TypeError as expected, and C2.foo() returns 42 .
>>> C1.__init__ <function Empty.__init__ at 0x7fa9a6c01400>
As you can see, it does not use object.__init__ , and does not even call its superclass ( object ) __init__
You can check it by calling __new__ yourself:
C2.__new__(C2) works just fine, while you get a regular TypeError with C1.__new__(C1)
So imho it's not as clear as
if you want an abstract base class, all its bases must be abstract.
While this is a good suggestion, the opposite is not necessarily true: neither OrderedDict nor Empty are abstract, and yet the first subclass is "concrete" and the last is "abstract"
If you're interested, I used OrderedDict in the example instead of list , because the latter is a "built-in" type, and you cannot do this:
OrderedDict.bar = lambda self: 42
And I wanted to make it clear that the problem is not related to it.
berdario
source share