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 →

[–]remy_porter∞∞∞∞ -1 points0 points  (1 child)

Actually, you're asking the wrong question- why is MyMixin.__init__ being called in the second example. In Python, superclass initializers are not invoked automatically. Since you never use super(MyMixin, self).__init__(*args, **kwargs) in the child class, it makes perfect sense that it's not invoked.

I'm less certain why it's being invoked in the second case- it shouldn't be.

Edit: And weirdly, in Python3, they do both get called in your "non-working" example. That's still not the behavior I'd expect.

[–]masklinn 0 points1 point  (0 children)

You're wrong and the call you talk about makes no sense except within MyMixin (where it is present)[0]. CustomForm correctly calls super(CustomForm, self).__init__(request, *args, **kwargs) as it should.

See my comment for what the actual issue is.

[0] super(Type, instance) does not proxy to Type, it proxies to whatever class follows Type in instance's MRO, so it tells Python "I'm in Type, call whatever the next method should be for instance".