From 4f003274cbdc7931ffcf9ad4809b5e3fb8cf5d9b Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Sun, 22 Oct 2023 12:52:25 +0300 Subject: [PATCH] [django-filter] Various minor fixes --- stubs/django-filter/@tests/stubtest_allowlist.txt | 2 +- stubs/django-filter/django_filters/fields.pyi | 9 ++++++--- stubs/django-filter/django_filters/filters.pyi | 6 ++++-- stubs/django-filter/django_filters/models.pyi | 0 stubs/django-filter/django_filters/views.pyi | 3 ++- stubs/django-filter/django_filters/widgets.pyi | 11 +++++++++-- 6 files changed, 22 insertions(+), 9 deletions(-) delete mode 100644 stubs/django-filter/django_filters/models.pyi diff --git a/stubs/django-filter/@tests/stubtest_allowlist.txt b/stubs/django-filter/@tests/stubtest_allowlist.txt index 48ae9e6ae4ba..d266723ddf4e 100644 --- a/stubs/django-filter/@tests/stubtest_allowlist.txt +++ b/stubs/django-filter/@tests/stubtest_allowlist.txt @@ -8,12 +8,12 @@ django_filters.RemovedInDjangoFilter25Warning django_filters.fields.BaseCSVWidget.surrogate django_filters.fields.CSVWidget.__init__ django_filters.fields.DJANGO_50 +django_filters.filters.__all__ django_filters.filters.Filter.__init__ django_filters.filters.NumberFilter.get_max_validator django_filters.filterset.BaseFilterSet.filter_for_field django_filters.filterset.FilterSet.base_filters django_filters.filterset.FilterSet.declared_filters -django_filters.models django_filters.rest_framework.DjangoFilterBackend django_filters.rest_framework.Filter.__init__ django_filters.rest_framework.FilterSet.base_filters diff --git a/stubs/django-filter/django_filters/fields.pyi b/stubs/django-filter/django_filters/fields.pyi index 59a866e5f60f..ed07338fe4d9 100644 --- a/stubs/django-filter/django_filters/fields.pyi +++ b/stubs/django-filter/django_filters/fields.pyi @@ -1,6 +1,7 @@ -from typing import Any +from typing import Any, TypeVar from django import forms +from django.db.models import Model from .conf import settings as settings from .constants import EMPTY_VALUES as EMPTY_VALUES @@ -13,6 +14,8 @@ from .widgets import ( RangeWidget as RangeWidget, ) +_M = TypeVar("_M", bound=Model) + class RangeField(forms.MultiValueField): widget: Any = ... def __init__(self, fields: Any | None = ..., *args: Any, **kwargs: Any) -> None: ... @@ -85,9 +88,9 @@ class MultipleChoiceField(ChoiceIteratorMixin, forms.MultipleChoiceField): empty_label: Any = ... def __init__(self, *args: Any, **kwargs: Any) -> None: ... -class ModelChoiceField(ChoiceIteratorMixin, forms.ModelChoiceField): +class ModelChoiceField(ChoiceIteratorMixin, forms.ModelChoiceField[_M]): iterator: Any = ... def to_python(self, value: Any): ... -class ModelMultipleChoiceField(ChoiceIteratorMixin, forms.ModelMultipleChoiceField): +class ModelMultipleChoiceField(ChoiceIteratorMixin, forms.ModelMultipleChoiceField[_M]): iterator: Any = ... diff --git a/stubs/django-filter/django_filters/filters.pyi b/stubs/django-filter/django_filters/filters.pyi index 10697beb231e..db363f11da0e 100644 --- a/stubs/django-filter/django_filters/filters.pyi +++ b/stubs/django-filter/django_filters/filters.pyi @@ -1,4 +1,6 @@ -from typing import Any, Callable +from _typeshed import Incomplete +from collections.abc import Callable +from typing import Any class Filter: creation_counter: int = ... @@ -20,7 +22,7 @@ class Filter: **kwargs: Any, ) -> None: ... def get_method(self, qs: Any): ... - method: Callable = ... + method: Callable[..., Incomplete] = ... label: Any = ... @property def field(self): ... diff --git a/stubs/django-filter/django_filters/models.pyi b/stubs/django-filter/django_filters/models.pyi deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/stubs/django-filter/django_filters/views.pyi b/stubs/django-filter/django_filters/views.pyi index 482056c8029f..fc36dcf123ea 100644 --- a/stubs/django-filter/django_filters/views.pyi +++ b/stubs/django-filter/django_filters/views.pyi @@ -1,3 +1,4 @@ +from _typeshed import Incomplete from typing import Any from django.views.generic import View @@ -19,7 +20,7 @@ class FilterMixin(metaclass=FilterMixinRenames): def get_filterset_kwargs(self, filterset_class: Any): ... def get_strict(self): ... -class BaseFilterView(FilterMixin, MultipleObjectMixin, View): +class BaseFilterView(FilterMixin, MultipleObjectMixin[Incomplete], View): filterset: Any = ... object_list: Any = ... def get(self, request: Any, *args: Any, **kwargs: Any): ... diff --git a/stubs/django-filter/django_filters/widgets.pyi b/stubs/django-filter/django_filters/widgets.pyi index 2e9f387944e5..163abbe839d1 100644 --- a/stubs/django-filter/django_filters/widgets.pyi +++ b/stubs/django-filter/django_filters/widgets.pyi @@ -1,10 +1,12 @@ +from _typeshed import Incomplete from typing import Any +from typing_extensions import TypeAlias from django import forms from django.forms.renderers import BaseRenderer from django.utils.safestring import SafeText -_OptAttrs = dict[str, Any] +_OptAttrs: TypeAlias = dict[str, Any] class LinkWidget(forms.Widget): choices: Any = ... @@ -12,7 +14,12 @@ class LinkWidget(forms.Widget): data: Any = ... def value_from_datadict(self, data: Any, files: Any, name: Any): ... def render( # type: ignore[override] - self, name: str, value: Any, attrs: _OptAttrs | None = ..., choices: tuple = ..., renderer: BaseRenderer | None = ... + self, + name: str, + value: Any, + attrs: _OptAttrs | None = ..., + choices: tuple[Incomplete, ...] = ..., + renderer: BaseRenderer | None = ..., ) -> SafeText: ... def render_options(self, choices: Any, selected_choices: Any, name: Any): ... def render_option(self, name: Any, selected_choices: Any, option_value: Any, option_label: Any): ...