While your wording wasn't quite right (the arguments are actually passed from the subclass to the superclass), the answer is yes, you need to manually pass the arguments in for super().__init__(*args, **kwargs)
. Otherwise you will encounter a TypeError
complaining about the missing required positional/keyword arguments.
In your example, it seemed unnecessary but you trimmed a key line after the super().__init__()
:
class ElectricCar(Car):
def __init__(self, make, model, year):
super().__init__(make, model, year)
self.battery = Battery()
This makes it necessary to redefine the __init__
in your subclass ElectricCar
, as Car
doesn't have the attribute battery
.
Note that for immutable superclass however, you don't need to pass in any argument:
class Foo(int):
def __init__(self, value):
self.value = value
super().__init__()
It would just take your subclass arguments as is at the point of __new__()
. In this case, if you did manually pass in any argument, to the super().__init()
, the interpreter would complain that the superclass's __init__
method doesn't take any argument. You can quickly see why this seems useless, but here's a related question on properly inheriting from str
/int
(if necessary).