3 ms·
> every class should always call super().__init__() For this to work, should every class also have an __init__ method that accepts zero arguments?
by pansa2 6y ago
> every class should always call super().__init__()
For this to work, should every class also have an __init__ method that accepts zero arguments?
- mehrdadn 6y agoThat's an excellent question and this opens the door to another another interesting discussion. I don't have the energy for that unfortunately, but to reply to your comment: it's not really important that it succeeds per se. Drastically increasing the likelihood of an error is good enough. What's important is that it mitigates the chances of introducing a bug silently.
- glyph 6y agoThere’s no error in the original example; in Python, the ability to participate in inheritance diamonds with arbitrary other classes is a feature which must be explicitly documented and maintained. James Knight wrote a really good piece on this many years ago: https://fuhm.net/super-harmful/ https://fuhm.net/super-harmful/ The solution is just to avoid inheritance. It’s full of terrible pitfalls in most languages, but Python more than most.