python-fmrest icon indicating copy to clipboard operation
python-fmrest copied to clipboard

Initializer doesn't call super(), breaking MRO

Open rothloup opened this issue 5 years ago • 2 comments

Server().init appears to have no call to super(), which breaks MRO when creating a class user Server() as one of several baseclasses (multiple inheritance). This can break other class's code because it fails to call init() on classes that come after Server().init() in the MRO. Please add a super() call to all class initializers that can be sub-classed.

rothloup avatar Aug 10 '20 20:08 rothloup

Thanks for the issue and PR, and sorry it took some time to respond.

To be honest, I never had the need to use multiple inheritance with fmrest, that's why those supers are missing. I would be interested in learning more about your use case, though.

I also added a few comments on your PR.

davidhamann avatar Oct 06 '20 16:10 davidhamann

Looks like it took me even longer to respond.

So my use case is fairly straightforward - I have a standard practice of adding logging to most of my classes. I do this by making each class a Logger, like this:

class MyFmDb(MyLogger, Server):

This is the classic case of multiple inheritance which MRO is built around.

If all the super() calls were constructed properly, I could simply call "super()", pass any args my constructor didn't consume, and be done with it. Instead, I have to manually ensure that I setup my own classes first, then call super to your "Server" base class.

I can handle this case in my own source code because that's where the inheritance tree splits - but it's especially bad if the problem is buried in a library.

rothloup avatar Oct 18 '22 19:10 rothloup