Right now, I have two sets of python mixins, A and B.
Let (A_1, A_2, ..., A_i, ...)
and (B_1, B_2, ..., B_i, ...)
, be the elements in these sets, respectively.
I want to make classes that are the cross between these two mixin sets and be able to references the elements of the cross by name. Is there some nice way in python to do this? Specifically, if say I have mixins
class A_1():
pass
class A_2():
pass
class B_1():
pass
class B_2():
pass
I want to be able to generate classes:
class A_1B_1(A_1, B_1):
pass
class A_1B_2(A_1, B_2):
pass
class A_2B_1(A_2, B_1):
pass
class A_2B_2(A_2, B_2):
pass
What's the best way to do that?
Additionally, let's say I want to add a new mixin to set B, call it B_x
. Is there a nice way to define some function that I can call on B_x
to generate the classes that would result from crossing all of the A_i
with B_x
? I.e., is there a function f
that I can write such that
f(B_x, [A_1, A_2, ..., A_n])
would result in being able to generate
class A_1B_x(A_1, B_x):
pass
class A_2B_x(A_2, B_x):
pass
# ... and so on
Notably, I want to be able to references these generated classes in another file to instantiate them by name.
Digging around, I found things like Dynamically mixin a base class to an instance in Python but they change an instance rather than generating classes.