Skip to content

Commit 813dd8c

Browse files
authored
make types for generic mixins less strict (#168)
1 parent 2b53fa5 commit 813dd8c

File tree

4 files changed

+9
-35
lines changed

4 files changed

+9
-35
lines changed

django-stubs/views/generic/dates.pyi

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import datetime
2-
from typing import Any, Dict, Optional, Sequence, Tuple, Type
2+
from typing import Any, Dict, Optional, Sequence, Tuple
33

4-
from django.db import models
5-
from django.http import HttpRequest, HttpResponse
64
from django.views.generic.base import View
75
from django.views.generic.detail import BaseDetailView, SingleObjectTemplateResponseMixin
86
from django.views.generic.list import MultipleObjectMixin, MultipleObjectTemplateResponseMixin
97

8+
from django.db import models
9+
from django.http import HttpRequest, HttpResponse
10+
1011
class YearMixin:
1112
year_format: str = ...
1213
year: Optional[str] = ...
13-
kwargs: Dict[str, Any] = ...
14-
request: HttpRequest = ...
1514
def get_year_format(self) -> str: ...
1615
def get_year(self) -> str: ...
1716
def get_next_year(self, date: datetime.date) -> Optional[datetime.date]: ...
@@ -20,8 +19,6 @@ class YearMixin:
2019
class MonthMixin:
2120
month_format: str = ...
2221
month: Optional[str] = ...
23-
request: HttpRequest = ...
24-
kwargs: Dict[str, Any] = ...
2522
def get_month_format(self) -> str: ...
2623
def get_month(self) -> str: ...
2724
def get_next_month(self, date: datetime.date) -> Optional[datetime.date]: ...
@@ -30,8 +27,6 @@ class MonthMixin:
3027
class DayMixin:
3128
day_format: str = ...
3229
day: Optional[str] = ...
33-
request: HttpRequest = ...
34-
kwargs: Dict[str, Any] = ...
3530
def get_day_format(self) -> str: ...
3631
def get_day(self) -> str: ...
3732
def get_next_day(self, date: datetime.date) -> Optional[datetime.date]: ...
@@ -40,8 +35,6 @@ class DayMixin:
4035
class WeekMixin:
4136
week_format: str = ...
4237
week: Optional[str] = ...
43-
request: HttpRequest = ...
44-
kwargs: Dict[str, Any] = ...
4538
def get_week_format(self) -> str: ...
4639
def get_week(self) -> str: ...
4740
def get_next_week(self, date: datetime.date) -> Optional[datetime.date]: ...
@@ -50,7 +43,6 @@ class WeekMixin:
5043
class DateMixin:
5144
date_field: Optional[str] = ...
5245
allow_future: bool = ...
53-
model: Optional[Type[models.Model]] = ...
5446
def get_date_field(self) -> str: ...
5547
def get_allow_future(self) -> bool: ...
5648
def uses_datetime_field(self) -> bool: ...

django-stubs/views/generic/detail.pyi

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
1-
from typing import Any, Dict, Optional, Type
1+
from typing import Any, Optional, Type
22

33
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
44

55
from django.db import models
66
from django.http import HttpRequest, HttpResponse
77

88
class SingleObjectMixin(ContextMixin):
9-
model: Optional[Type[models.Model]] = ...
10-
queryset: Optional[models.query.QuerySet] = ...
9+
model: Type[models.Model] = ...
10+
queryset: models.query.QuerySet = ...
1111
slug_field: str = ...
12-
context_object_name: Optional[str] = ...
12+
context_object_name: str = ...
1313
slug_url_kwarg: str = ...
1414
pk_url_kwarg: str = ...
1515
query_pk_and_slug: bool = ...
16-
object: models.Model = ...
17-
kwargs: Dict[str, Any] = ...
1816
def get_object(self, queryset: Optional[models.query.QuerySet] = ...) -> models.Model: ...
1917
def get_queryset(self) -> models.query.QuerySet: ...
2018
def get_slug_field(self) -> str: ...
2119
def get_context_object_name(self, obj: Any) -> Optional[str]: ...
2220

2321
class BaseDetailView(SingleObjectMixin, View):
24-
def render_to_response(self, context: Dict[str, Any], **response_kwargs: Any) -> HttpResponse: ...
2522
def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
2623

2724
class SingleObjectTemplateResponseMixin(TemplateResponseMixin):
2825
template_name_field: Optional[str] = ...
2926
template_name_suffix: str = ...
30-
model: Optional[Type[models.Model]] = ...
31-
object: models.Model = ...
3227

3328
class DetailView(SingleObjectTemplateResponseMixin, BaseDetailView): ...

django-stubs/views/generic/edit.pyi

-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Any, Callable, Dict, Optional, Sequence, Type, Union
22

3-
from django.db import models
43
from django.forms.forms import BaseForm
54
from django.http import HttpRequest, HttpResponse
65
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
@@ -12,8 +11,6 @@ class FormMixin(ContextMixin):
1211
form_class: Optional[Type[BaseForm]] = ...
1312
success_url: Optional[Union[str, Callable[..., Any]]] = ...
1413
prefix: Optional[str] = ...
15-
request: HttpRequest = ...
16-
def render_to_response(self, context: Dict[str, Any], **response_kwargs: object) -> HttpResponse: ...
1714
def get_initial(self) -> Dict[str, Any]: ...
1815
def get_prefix(self) -> Optional[str]: ...
1916
def get_form_class(self) -> Type[BaseForm]: ...
@@ -27,8 +24,6 @@ class ModelFormMixin(FormMixin, SingleObjectMixin):
2724
fields: Optional[Union[Sequence[str], Literal["__all__"]]] = ...
2825

2926
class ProcessFormView(View):
30-
def render_to_response(self, context: Dict[str, Any], **response_kwargs: Any) -> HttpResponse: ...
31-
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ...
3227
def get(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
3328
def post(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
3429
def put(self, *args: str, **kwargs: Any) -> HttpResponse: ...
@@ -40,11 +35,8 @@ class CreateView(SingleObjectTemplateResponseMixin, BaseCreateView): ...
4035
class BaseUpdateView(ModelFormMixin, ProcessFormView): ...
4136
class UpdateView(SingleObjectTemplateResponseMixin, BaseUpdateView): ...
4237

43-
_object = object
44-
4538
class DeletionMixin:
4639
success_url: Optional[str] = ...
47-
object: models.Model = ...
4840
def post(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
4941
def delete(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
5042
def get_success_url(self) -> str: ...

django-stubs/views/generic/list.pyi

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Optional, Sequence, Tuple, Type
1+
from typing import Any, Optional, Sequence, Tuple, Type
22

33
from django.core.paginator import Paginator
44
from django.db.models.query import QuerySet, _BaseQuerySet
@@ -17,9 +17,6 @@ class MultipleObjectMixin(ContextMixin):
1717
paginator_class: Type[Paginator] = ...
1818
page_kwarg: str = ...
1919
ordering: Sequence[str] = ...
20-
request: HttpRequest = ...
21-
kwargs: Dict[str, Any] = ...
22-
object_list: QuerySet = ...
2320
def get_queryset(self) -> QuerySet: ...
2421
def get_ordering(self) -> Sequence[str]: ...
2522
def paginate_queryset(self, queryset: _BaseQuerySet, page_size: int) -> Tuple[Paginator, int, QuerySet, bool]: ...
@@ -32,11 +29,9 @@ class MultipleObjectMixin(ContextMixin):
3229
def get_context_object_name(self, object_list: _BaseQuerySet) -> Optional[str]: ...
3330

3431
class BaseListView(MultipleObjectMixin, View):
35-
def render_to_response(self, context: Dict[str, Any], **response_kwargs: Any) -> HttpResponse: ...
3632
def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
3733

3834
class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
3935
template_name_suffix: str = ...
40-
object_list: QuerySet = ...
4136

4237
class ListView(MultipleObjectTemplateResponseMixin, BaseListView): ...

0 commit comments

Comments
 (0)