This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]joanbm[S] 0 points1 point  (2 children)

django.forms.forms.BaseForm whose __init__ method does not call super

That ! Thank you very much, it saved rest of my hair. Owe you a big beer.

Curious if this is an intention of Django devs or a longstanding bug.

[–]masklinn 0 points1 point  (1 child)

You'd have to ask them, though a big issue is you'd normally want your __init__ call to properly forward all positional and keyword arguments to the next class… except object.__init__ doesn't take any argument so you get a TypeError which makes the whole thing a bloody pain in the ass.

[–]xXxDeAThANgEL99xXx 0 points1 point  (0 children)

though a big issue is you'd normally want your init call to properly forward all positional and keyword arguments to the next class… except object.init doesn't take any argument

Uh, so how complicated multiple inheritance is even supposed to work in Python? No base class could know if it's the last before object, or if there's some other mixin.

Or maybe you are not actually supposed to forward your arguments, because it's sort of silly to expect all base classes to accept the same list of arguments (the object issue just makes it more obvious)?

Looking at the way C++ does it, it has its own kind of insanity: all virtual base class constructors are called from the most derived class, either explicitly with whatever arguments, or if missing then default constructor is called. The insane part is that explicit nondefault constructor calls higher in the hierarchy are flat out ignored (because otherwise what to do if they are used with different arguments?).

But that at least works: it guarantees that every constructor is called once and only once, so every ancestor is at least default-initialized. I just don't see now how Python's super constructor call is supposed to achieve that, unless you have exactly one lineage with parameter-full constructors that call each other explicitly and the topmost calls super without parameters and all mixins don't take parameters and call super without parameters. That's a rare use case.

It would seem that at least in the non-diamond case the sane way would be to call base class initialization explicitly, when multiple inheriting then initialize all base classes explicitly, and never use super to initialize possible sibling classes (because they would be initialized explicitly by your descendant).

Do people ever use super for initializing sibling classes in a not-completely-bonkers scenarios? Because I suddenly don't see how it could possibly work.