I was wondering if there is generic inheritance in python.
For example,
Class A(object):
def foo():
Class B(object):
def foo():
Class C(<someParentClass>):
def bar():
so effectively, I would like to do something like
myClass1 = C()<A>
myClass2 = C()<B>
Im guessing this is not possible in python, but is there any other way to have a similar effect?
There’s nothing preventing it. Everything in Python is essentially generic. Everything is runtime, including class statements, so you can do something like:
If you want the C class to be a little more descriptive in name or documentation, you can assign the
__name__and__doc__attributes, or use the three-argument form oftype()instead of theclassstatement to create it.