Suppose I have a python class with arguments in the __init__ method with types specified.
class A:
def __init__(self, arg_1:int, ..., arg_n:int):
pass
Suppose I inherit from it as such:
class B(A):
def __init__(self, arg_2:int, ..., arg_n:int):
super().__init__(arg1="str", arg_2, ..., arg_n)
The problem here is that I have to write the the whole argument list including the types. If I decide to change the type of one argument to some other type, I have to do so for all subclasses. How can we avoid this?
One possible solution could be the one below. However, the constructor here does not show the list of arguments as they are defined in Class A.
class B(A):
def __init__(self, **kwargs):
super().__init__(arg1="str", **kwargs)
Is it maybe possible to group the common arguments in one class and share that in all classes?
dataclassto create aParamsobject containing the arguments and instantiate bothAandBwith an object of classParams?super().__init__refers toA.__init__, as it depends entirely on the runtime type ofself. As such, it's not really a problem that it doesn't listA's parameters, because there might be more than justA's parameters that need to be filled.