Skip to content

Commit

Permalink
[django-filter] Various minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
intgr committed Dec 22, 2024
1 parent 8956aaf commit 4f00327
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion stubs/django-filter/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions stubs/django-filter/django_filters/fields.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...
Expand Down Expand Up @@ -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 = ...
6 changes: 4 additions & 2 deletions stubs/django-filter/django_filters/filters.pyi
Original file line number Diff line number Diff line change
@@ -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 = ...
Expand All @@ -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): ...
Expand Down
Empty file.
3 changes: 2 additions & 1 deletion stubs/django-filter/django_filters/views.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Incomplete
from typing import Any

from django.views.generic import View
Expand All @@ -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): ...
Expand Down
11 changes: 9 additions & 2 deletions stubs/django-filter/django_filters/widgets.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
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 = ...
def __init__(self, attrs: Any | None = ..., choices: Any = ...) -> None: ...
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): ...
Expand Down

0 comments on commit 4f00327

Please sign in to comment.