Call super in BaseForm.__init__
|Reported by:||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently /django/forms/forms.py BaseForm.__init__ (as well as a fair number of other classes) does not call super().__init__. This makes it impossible to create form mixins.
from django import forms class FormMixin(object): def __init__(self, *args, **kwargs): super(FormMixin, self).__init__(*args, **kwargs) self.my_flag = true class MyForm(forms.Form, FormMixin): field1 = forms.CharField() class MyModelForm(forms.ModelForm, FormMixin): class Meta(object): model = SpamModel
Because of python's mro the init() in the mixin never gets called because BaseForm.__init__ does not call it.
Ideally, all classes in django that have an __init__() should also call super().__init__()