I'm having a problem with multiple inheritance that I can't seem to figure out. Here is a very abstracted minimal example that reproduces my error (my code is much more complex than this).
class Thing(object):
def __init__(self, x=None):
self.x = x
class Mixin(object):
def __init__(self):
self.numbers = [1,2,3]
def children(self):
return [super().__init__(x=num) for num in self.numbers]
class CompositeThing(Mixin, Thing):
def __init__(self):
super().__init__()
def test(self):
for child in self.children():
print(child.x)
obj = CompositeThing()
obj.test()
Per this, I expect the children()
method to return a list of Thing
s built up from self.numbers
. Instead, I get TypeError: super(type, obj): obj must be an instance or subtype of type
. Incidentally, the same thing happens if I don't call the constructor and allow children to return super()
3 times (i.e., the uninstantiated superclass). Any ideas why this might be happening?
Thanks in advance!