1
- from typing import Any , Callable , Dict , Optional , Sequence , Type , Union
1
+ from typing import Any , Callable , Dict , Generic , Optional , Sequence , Type , TypeVar , Union
2
2
3
3
from django .forms .forms import BaseForm
4
4
from django .forms .models import BaseModelForm
@@ -8,6 +8,8 @@ from typing_extensions import Literal
8
8
9
9
from django .http import HttpRequest , HttpResponse
10
10
11
+ _FormT = TypeVar ('_FormT' , bound = BaseForm )
12
+
11
13
class AbstractFormMixin (ContextMixin ):
12
14
initial : Dict [str , Any ] = ...
13
15
form_class : Optional [Type [BaseForm ]] = ...
@@ -18,11 +20,11 @@ class AbstractFormMixin(ContextMixin):
18
20
def get_form_kwargs (self ) -> Dict [str , Any ]: ...
19
21
def get_success_url (self ) -> str : ...
20
22
21
- class FormMixin (AbstractFormMixin ):
22
- def get_form_class (self ) -> Type [BaseForm ]: ...
23
- def get_form (self , form_class : Optional [Type [BaseForm ]] = ...) -> BaseForm : ...
24
- def form_valid (self , form : BaseForm ) -> HttpResponse : ...
25
- def form_invalid (self , form : BaseForm ) -> HttpResponse : ...
23
+ class FormMixin (Generic [ _FormT ], AbstractFormMixin ):
24
+ def get_form_class (self ) -> Type [_FormT ]: ...
25
+ def get_form (self , form_class : Optional [Type [_FormT ]] = ...) -> BaseForm : ...
26
+ def form_valid (self , form : _FormT ) -> HttpResponse : ...
27
+ def form_invalid (self , form : _FormT ) -> HttpResponse : ...
26
28
27
29
class ModelFormMixin (AbstractFormMixin , SingleObjectMixin ):
28
30
fields : Optional [Union [Sequence [str ], Literal ["__all__" ]]] = ...
@@ -36,8 +38,8 @@ class ProcessFormView(View):
36
38
def post (self , request : HttpRequest , * args : str , ** kwargs : Any ) -> HttpResponse : ...
37
39
def put (self , * args : str , ** kwargs : Any ) -> HttpResponse : ...
38
40
39
- class BaseFormView (FormMixin , ProcessFormView ): ...
40
- class FormView (TemplateResponseMixin , BaseFormView ): ...
41
+ class BaseFormView (FormMixin [ _FormT ] , ProcessFormView ): ...
42
+ class FormView (TemplateResponseMixin , BaseFormView [ _FormT ] ): ...
41
43
class BaseCreateView (ModelFormMixin , ProcessFormView ): ...
42
44
class CreateView (SingleObjectTemplateResponseMixin , BaseCreateView ): ...
43
45
class BaseUpdateView (ModelFormMixin , ProcessFormView ): ...
0 commit comments