The typical way to do subclassing in Python is this
class Base:
def __init__(self):
self.base = 1
class Sub(Base):
def __init__(self):
self.sub = 2
super().__init__()
And this allows me to create an instance of type Sub that can access both base and sub properties.
However, I'm using an api that returns a list of Base instances, and I need to convert each instance of Base into an instance of Sub. Because this is an API that is subject to change, I don't want to specifically unpack each property and reassign them by hand.
How can this be done in Python3?
*argsand**kwargs?Baseobject into aSubobject. Perhaps this can be done inSub.__init__or perhaps you write a class method inSubthat knows how. Or even just a stand-alone function. Alternately, perhapsSubshouldn't inherit fromBaseat all and just do composition by keeping aBasemember variable. Lots of choices!