I wrote classes with diamond inheritance. Were there are two classes at same level the constructors have different length of arguments list and depending on declaration order in list of bases declaration everything works fine or error in thrown immediately
class DFT(Common.BaseAS, Common.Signal):
def __init__(self, fs, N, history_len=1, strict=False):
super().__init__(fs, N, history_len, strict, np.complex)
class BaseAS(abc.ABC, AnalysisResultSaver):
No constructor here
class AnalysisResultSaver(Base):
def __init__(self, fs=8000, N=250, history_len=1, strict=False, dtype=None):
super().__init__(fs, N, dtype)
class Signal(Base):
def __init__(self, fs, N, dtype=None):
super().__init__(fs, N, dtype)
class Base:
def __init__(self, fs, N, dtype=None):
Stuff
Constructors are called in order:
DFT;
AnalysisResultSaver;
Signal;
Base;
In this case everything works fine but my question is
1) how are arguments passed to Signal constructor if there's no direct indication which arguments are right ones, is it just trimmed to first two?
But if I change order of bases in DFT then I get
super().__init__(fs, N, history_len, strict, np.complex)
TypeError: __init__() takes from 3 to 4 positional arguments but 6 were given
I know it changes mro but in first case it works fine
and if I want to call constructors directly by Common.BaseAS.__init__()
and Common.Signal.__init__() than Signal constructor is called twice so somehow call to BaseAS calls Signal constructor even though it's not its parent.
Common.BaseAS.__init__(self, fs, N, history_len, strict, np.complex)
Common.Signal.__init__(self, fs, N)
So 2) how can BaseAS call Signal constuctor?