I try to use multiple inheritance. Tank is both Vehicle and Weapon:
class Weapon:
def __init__(self, name, strength, *args, **kwargs):
super().__init__(*args, **kwargs)
class Vehicle:
def __init__(self, name, average_speed, *args, **kwargs):
super().__init__(*args, **kwargs)
class Tank(Weapon, Vehicle):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Tank(name="Moshe", average_speed=68, weight=62.5, strength=17.7)
So the Tank's MRO is [__main__.Tank, __main__.Weapon, __main__.Vehicle, object].
Unfortunately, both Weapon and Vehicle have the name parameter, so currently the following error happens:
TypeError: __init__() missing 1 required positional argument: 'name'
Is there a non-artificial way to pass it through all the superclasses?
Moshe? That wouldn't be my first guess. Perhaps the name should be a property of theTank? MAybe theTankshould use composition rather than inheritance? Seems to me that a tank is not a weapon for example, but it may have a few.Weapon.nameandVehicle.nameactually supposed to have the same meaning? Is there a reason why "thing with name" isn't a separate type, i.e.class Tank(Weapon, Vehicle, Named):?