Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make types for generic View mixins less strict #168

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions django-stubs/views/generic/dates.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import datetime
from typing import Any, Dict, Optional, Sequence, Tuple, Type
from typing import Any, Dict, Optional, Sequence, Tuple

from django.db import models
from django.http import HttpRequest, HttpResponse
from django.views.generic.base import View
from django.views.generic.detail import BaseDetailView, SingleObjectTemplateResponseMixin
from django.views.generic.list import MultipleObjectMixin, MultipleObjectTemplateResponseMixin

from django.db import models
from django.http import HttpRequest, HttpResponse

class YearMixin:
year_format: str = ...
year: Optional[str] = ...
kwargs: Dict[str, Any] = ...
request: HttpRequest = ...
def get_year_format(self) -> str: ...
def get_year(self) -> str: ...
def get_next_year(self, date: datetime.date) -> Optional[datetime.date]: ...
Expand All @@ -20,8 +19,6 @@ class YearMixin:
class MonthMixin:
month_format: str = ...
month: Optional[str] = ...
request: HttpRequest = ...
kwargs: Dict[str, Any] = ...
def get_month_format(self) -> str: ...
def get_month(self) -> str: ...
def get_next_month(self, date: datetime.date) -> Optional[datetime.date]: ...
Expand All @@ -30,8 +27,6 @@ class MonthMixin:
class DayMixin:
day_format: str = ...
day: Optional[str] = ...
request: HttpRequest = ...
kwargs: Dict[str, Any] = ...
def get_day_format(self) -> str: ...
def get_day(self) -> str: ...
def get_next_day(self, date: datetime.date) -> Optional[datetime.date]: ...
Expand All @@ -40,8 +35,6 @@ class DayMixin:
class WeekMixin:
week_format: str = ...
week: Optional[str] = ...
request: HttpRequest = ...
kwargs: Dict[str, Any] = ...
def get_week_format(self) -> str: ...
def get_week(self) -> str: ...
def get_next_week(self, date: datetime.date) -> Optional[datetime.date]: ...
Expand All @@ -50,7 +43,6 @@ class WeekMixin:
class DateMixin:
date_field: Optional[str] = ...
allow_future: bool = ...
model: Optional[Type[models.Model]] = ...
def get_date_field(self) -> str: ...
def get_allow_future(self) -> bool: ...
def uses_datetime_field(self) -> bool: ...
Expand Down
13 changes: 4 additions & 9 deletions django-stubs/views/generic/detail.pyi
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
from typing import Any, Dict, Optional, Type
from typing import Any, Optional, Type

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

from django.db import models
from django.http import HttpRequest, HttpResponse

class SingleObjectMixin(ContextMixin):
model: Optional[Type[models.Model]] = ...
queryset: Optional[models.query.QuerySet] = ...
model: Type[models.Model] = ...
queryset: models.query.QuerySet = ...
slug_field: str = ...
context_object_name: Optional[str] = ...
context_object_name: str = ...
slug_url_kwarg: str = ...
pk_url_kwarg: str = ...
query_pk_and_slug: bool = ...
object: models.Model = ...
kwargs: Dict[str, Any] = ...
def get_object(self, queryset: Optional[models.query.QuerySet] = ...) -> models.Model: ...
def get_queryset(self) -> models.query.QuerySet: ...
def get_slug_field(self) -> str: ...
def get_context_object_name(self, obj: Any) -> Optional[str]: ...

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

class SingleObjectTemplateResponseMixin(TemplateResponseMixin):
template_name_field: Optional[str] = ...
template_name_suffix: str = ...
model: Optional[Type[models.Model]] = ...
object: models.Model = ...

class DetailView(SingleObjectTemplateResponseMixin, BaseDetailView): ...
8 changes: 0 additions & 8 deletions django-stubs/views/generic/edit.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any, Callable, Dict, Optional, Sequence, Type, Union

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

class ProcessFormView(View):
def render_to_response(self, context: Dict[str, Any], **response_kwargs: Any) -> HttpResponse: ...
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ...
def get(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
def post(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
def put(self, *args: str, **kwargs: Any) -> HttpResponse: ...
Expand All @@ -40,11 +35,8 @@ class CreateView(SingleObjectTemplateResponseMixin, BaseCreateView): ...
class BaseUpdateView(ModelFormMixin, ProcessFormView): ...
class UpdateView(SingleObjectTemplateResponseMixin, BaseUpdateView): ...

_object = object

class DeletionMixin:
success_url: Optional[str] = ...
object: models.Model = ...
def post(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
def delete(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
def get_success_url(self) -> str: ...
Expand Down
7 changes: 1 addition & 6 deletions django-stubs/views/generic/list.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional, Sequence, Tuple, Type
from typing import Any, Optional, Sequence, Tuple, Type

from django.core.paginator import Paginator
from django.db.models.query import QuerySet, _BaseQuerySet
Expand All @@ -17,9 +17,6 @@ class MultipleObjectMixin(ContextMixin):
paginator_class: Type[Paginator] = ...
page_kwarg: str = ...
ordering: Sequence[str] = ...
request: HttpRequest = ...
kwargs: Dict[str, Any] = ...
object_list: QuerySet = ...
def get_queryset(self) -> QuerySet: ...
def get_ordering(self) -> Sequence[str]: ...
def paginate_queryset(self, queryset: _BaseQuerySet, page_size: int) -> Tuple[Paginator, int, QuerySet, bool]: ...
Expand All @@ -32,11 +29,9 @@ class MultipleObjectMixin(ContextMixin):
def get_context_object_name(self, object_list: _BaseQuerySet) -> Optional[str]: ...

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

class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
template_name_suffix: str = ...
object_list: QuerySet = ...

class ListView(MultipleObjectTemplateResponseMixin, BaseListView): ...