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

[django-filter] Absorb django-filter-stubs into typeshed #10919

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"stubs/click-default-group",
"stubs/commonmark",
"stubs/dateparser",
"stubs/django-filter",
"stubs/docutils",
"stubs/Flask-Migrate",
"stubs/Flask-SocketIO",
Expand Down
40 changes: 40 additions & 0 deletions stubs/django-filter/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
django_filters.Filter.__init__
django_filters.FilterMethod
django_filters.FilterSet.base_filters
django_filters.FilterSet.declared_filters
django_filters.NumberFilter.get_max_validator
django_filters.QuerySetRequestMixin
django_filters.RemovedInDjangoFilter25Warning
django_filters.fields.BaseCSVWidget.surrogate
django_filters.fields.CSVWidget.__init__
django_filters.fields.DJANGO_50
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.rest_framework.DjangoFilterBackend
django_filters.rest_framework.Filter.__init__
django_filters.rest_framework.FilterSet.base_filters
django_filters.rest_framework.FilterSet.declared_filters
django_filters.rest_framework.NumberFilter.get_max_validator
django_filters.rest_framework.__all__
django_filters.rest_framework.backends.DjangoFilterBackend
django_filters.rest_framework.backends.RenameAttributes
django_filters.rest_framework.filters.Filter.__init__
django_filters.rest_framework.filters.NumberFilter.get_max_validator
django_filters.rest_framework.filterset.FilterSet.base_filters
django_filters.rest_framework.filterset.FilterSet.declared_filters
django_filters.views.BaseFilterView
django_filters.views.FilterMixin
django_filters.views.FilterMixinRenames
django_filters.views.FilterView
django_filters.views.MigrationNotice
django_filters.views.RenameAttributesBase
django_filters.widgets.BaseCSVWidget.surrogate
django_filters.widgets.CSVWidget.__init__

# These fail due to DJANGO_SETTINGS_MODULE being unset
django_filters.compat
django_filters.conf
django_filters.utils
3 changes: 3 additions & 0 deletions stubs/django-filter/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version = "23.3.*"
upstream_repository = "https://github.com/carltongibson/django-filter"
requires = ["django-stubs", "djangorestframework-stubs"]
9 changes: 9 additions & 0 deletions stubs/django-filter/django_filters/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Any

from . import rest_framework as rest_framework
from .filters import *
from .filterset import FilterSet as FilterSet

def parse_version(version: Any): ...

VERSION: Any
1 change: 1 addition & 0 deletions stubs/django-filter/django_filters/compat.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def is_crispy(): ...
15 changes: 15 additions & 0 deletions stubs/django-filter/django_filters/conf.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Any

from .utils import deprecate as deprecate

DEFAULTS: Any
DEPRECATED_SETTINGS: Any

def is_callable(value: Any): ...

class Settings:
def __getattr__(self, name: Any): ...
def get_setting(self, setting: Any): ...
def change_setting(self, setting: Any, value: Any, enter: Any, **kwargs: Any) -> None: ...

settings: Any
4 changes: 4 additions & 0 deletions stubs/django-filter/django_filters/constants.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from typing import Any

ALL_FIELDS: str
EMPTY_VALUES: Any
6 changes: 6 additions & 0 deletions stubs/django-filter/django_filters/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from typing import Any

from django.core.exceptions import FieldError

class FieldLookupError(FieldError):
def __init__(self, model_field: Any, lookup_expr: Any) -> None: ...
93 changes: 93 additions & 0 deletions stubs/django-filter/django_filters/fields.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from typing import Any

from django import forms

from .conf import settings as settings
from .constants import EMPTY_VALUES as EMPTY_VALUES
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are lots of re-exports that shouldn't be re-exported. Should I clean these up before initial merge, or in follow-up?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow-up is fine imo

from .utils import handle_timezone as handle_timezone
from .widgets import (
BaseCSVWidget as BaseCSVWidget,
CSVWidget as CSVWidget,
DateRangeWidget as DateRangeWidget,
LookupChoiceWidget as LookupChoiceWidget,
RangeWidget as RangeWidget,
)

class RangeField(forms.MultiValueField):
widget: Any = ...
def __init__(self, fields: Any | None = ..., *args: Any, **kwargs: Any) -> None: ...
def compress(self, data_list: Any): ...

class DateRangeField(RangeField):
widget: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def compress(self, data_list: Any): ...

class DateTimeRangeField(RangeField):
widget: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class IsoDateTimeRangeField(RangeField):
widget: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class TimeRangeField(RangeField):
widget: Any = ...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I clean up attribute assignments?

Suggested change
widget: Any = ...
widget: Any

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine to do this in a follow-up imo

def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class Lookup:
def __new__(cls, value: Any, lookup_expr: Any): ...

class LookupChoiceField(forms.MultiValueField):
default_error_messages: Any = ...
def __init__(self, field: Any, lookup_choices: Any, *args: Any, **kwargs: Any) -> None: ...
def compress(self, data_list: Any): ...

class IsoDateTimeField(forms.DateTimeField):
ISO_8601: str = ...
input_formats: Any = ...
def strptime(self, value: Any, format: Any): ...

class BaseCSVField(forms.Field):
base_widget_class: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def clean(self, value: Any): ...

class BaseRangeField(BaseCSVField):
widget: Any = ...
default_error_messages: Any = ...
def clean(self, value: Any): ...

class ChoiceIterator:
field: Any = ...
choices: Any = ...
def __init__(self, field: Any, choices: Any) -> None: ...
def __iter__(self) -> Any: ...
def __len__(self): ...

class ModelChoiceIterator(forms.models.ModelChoiceIterator):
def __iter__(self) -> Any: ...
def __len__(self): ...

class ChoiceIteratorMixin:
null_label: Any = ...
null_value: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
choices: Any = ...

class ChoiceField(ChoiceIteratorMixin, forms.ChoiceField):
iterator: Any = ...
empty_label: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class MultipleChoiceField(ChoiceIteratorMixin, forms.MultipleChoiceField):
iterator: Any = ...
empty_label: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class ModelChoiceField(ChoiceIteratorMixin, forms.ModelChoiceField):
iterator: Any = ...
def to_python(self, value: Any): ...

class ModelMultipleChoiceField(ChoiceIteratorMixin, forms.ModelMultipleChoiceField):
iterator: Any = ...
174 changes: 174 additions & 0 deletions stubs/django-filter/django_filters/filters.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
from _typeshed import Incomplete
from collections.abc import Callable
from typing import Any

class Filter:
creation_counter: int = ...
field_class: Any = ...
field_name: Any = ...
lookup_expr: Any = ...
distinct: Any = ...
exclude: Any = ...
extra: Any = ...
def __init__(
self,
field_name: Any | None = ...,
lookup_expr: str = ...,
*,
label: Any | None = ...,
method: Any | None = ...,
distinct: bool = ...,
exclude: bool = ...,
**kwargs: Any,
) -> None: ...
def get_method(self, qs: Any): ...
method: Callable[..., Incomplete] = ...
label: Any = ...
@property
def field(self): ...
def filter(self, qs: Any, value: Any): ...

class CharFilter(Filter):
field_class: Any = ...

class BooleanFilter(Filter):
field_class: Any = ...

class ChoiceFilter(Filter):
field_class: Any = ...
null_value: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def filter(self, qs: Any, value: Any): ...

class TypedChoiceFilter(Filter):
field_class: Any = ...

class UUIDFilter(Filter):
field_class: Any = ...

class MultipleChoiceFilter(Filter):
field_class: Any = ...
always_filter: bool = ...
conjoined: Any = ...
null_value: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def is_noop(self, qs: Any, value: Any): ...
def filter(self, qs: Any, value: Any): ...
def get_filter_predicate(self, v: Any): ...

class TypedMultipleChoiceFilter(MultipleChoiceFilter):
field_class: Any = ...

class DateFilter(Filter):
field_class: Any = ...

class DateTimeFilter(Filter):
field_class: Any = ...

class IsoDateTimeFilter(DateTimeFilter):
field_class: Any = ...

class TimeFilter(Filter):
field_class: Any = ...

class DurationFilter(Filter):
field_class: Any = ...

class QuerySetRequestMixin:
queryset: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def get_request(self): ...
def get_queryset(self, request: Any): ...
@property
def field(self): ...

class ModelChoiceFilter(QuerySetRequestMixin, ChoiceFilter):
field_class: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class ModelMultipleChoiceFilter(QuerySetRequestMixin, MultipleChoiceFilter):
field_class: Any = ...

class NumberFilter(Filter):
field_class: Any = ...

class NumericRangeFilter(Filter):
field_class: Any = ...
lookup_expr: str = ...
def filter(self, qs: Any, value: Any): ...

class RangeFilter(Filter):
field_class: Any = ...
lookup_expr: str = ...
def filter(self, qs: Any, value: Any): ...

class DateRangeFilter(ChoiceFilter):
choices: Any = ...
filters: Any = ...
def __init__(self, choices: Any | None = ..., filters: Any | None = ..., *args: Any, **kwargs: Any) -> None: ...
def filter(self, qs: Any, value: Any): ...

class DateFromToRangeFilter(RangeFilter):
field_class: Any = ...

class DateTimeFromToRangeFilter(RangeFilter):
field_class: Any = ...

class IsoDateTimeFromToRangeFilter(RangeFilter):
field_class: Any = ...

class TimeRangeFilter(RangeFilter):
field_class: Any = ...

class AllValuesFilter(ChoiceFilter):
@property
def field(self): ...

class AllValuesMultipleFilter(MultipleChoiceFilter):
@property
def field(self): ...

class BaseCSVFilter(Filter):
base_field_class: Any = ...
field_class: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class BaseInFilter(BaseCSVFilter):
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class BaseRangeFilter(BaseCSVFilter):
base_field_class: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class LookupChoiceFilter(Filter):
field_class: Any = ...
outer_class: Any = ...
empty_label: Any = ...
lookup_choices: Any = ...
def __init__(
self, field_name: Any | None = ..., lookup_choices: Any | None = ..., field_class: Any | None = ..., **kwargs: Any
) -> None: ...
@classmethod
def normalize_lookup(cls, lookup: Any): ...
def get_lookup_choices(self): ...
@property
def field(self): ...
lookup_expr: Any = ...
def filter(self, qs: Any, lookup: Any): ...

class OrderingFilter(BaseCSVFilter, ChoiceFilter):
descending_fmt: Any = ...
param_map: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def get_ordering_value(self, param: Any): ...
def filter(self, qs: Any, value: Any): ...
@classmethod
def normalize_fields(cls, fields: Any): ...
def build_choices(self, fields: Any, labels: Any): ...

class FilterMethod:
f: Any = ...
def __init__(self, filter_instance: Any) -> None: ...
def __call__(self, qs: Any, value: Any): ...
@property
def method(self): ...
Loading
Loading