I am wanting to make a function that creates a new class from a variable amount of so-called mixin classes. My first instinct is to use *args
...
>>> def mixins(*args):
class Foo(*args):
SyntaxError: invalid syntax
... but didn't get very far ... Since that didn't work, I tried this, which seems to work:
>>> def mixins(*args):
class Foo(args[0]):
pass
for arg in args[1:]:
class Foo(Foo, arg):
pass
return Foo
Question
Are there other approaches to solving this problem?
Motivation
I have created an Abstract Base Class that has many abstract methods. I have several types of subclasses, which each implement some of the needed abstract methods but not all of them. Sometimes I can create a working instance by mixing in 2 subclasses, sometimes it takes more to implement all of the abstract methods.