Skip to content

Add parent property to Filter #17

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions django_filters-stubs/filters.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any, Callable, Optional

from django_filters.filterset import FilterSet

class Filter:
creation_counter: int = ...
field_class: Any = ...
Expand All @@ -22,6 +24,7 @@ class Filter:
def get_method(self, qs: Any): ...
method: Callable = ...
label: Any = ...
parent: FilterSet = ...
@property
def field(self): ...
def filter(self, qs: Any, value: Any): ...
Expand Down
4 changes: 2 additions & 2 deletions django_filters-stubs/filterset.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any, Dict, Optional

from .conf import settings
from .constants import ALL_FIELDS
Expand Down Expand Up @@ -44,7 +44,7 @@ class BaseFilterSet:
queryset: Any = ...
request: Any = ...
form_prefix: Any = ...
filters: Any = ...
filters: Dict[str, Filter] = ...
def __init__(
self,
data: Optional[Any] = ...,
Expand Down
5 changes: 4 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ black
flake8
isort
pytest-mypy-plugins
pip-tools
pip-tools

django-filter
pytest-watch
16 changes: 15 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ click==8.1.3
# via
# black
# pip-tools
colorama==0.4.6
# via pytest-watch
decorator==5.1.1
# via pytest-mypy-plugins
django==3.2.16
# via
# django-filter
# django-stubs
# django-stubs-ext
django-filter==22.1
# via -r requirements.in
django-stubs==1.13.1
# via
# django-filter-stubs
Expand All @@ -38,6 +43,8 @@ django-stubs-ext==0.7.0
# via django-stubs
djangorestframework-stubs==1.8.0
# via django-filter-stubs
docopt==0.6.2
# via pytest-watch
exceptiongroup==1.1.0
# via pytest
flake8==5.0.4
Expand Down Expand Up @@ -87,9 +94,13 @@ pycodestyle==2.9.1
pyflakes==2.5.0
# via flake8
pytest==7.2.0
# via pytest-mypy-plugins
# via
# pytest-mypy-plugins
# pytest-watch
pytest-mypy-plugins==1.10.1
# via -r requirements.in
pytest-watch==4.2.0
# via -r requirements.in
pytz==2022.7
# via django
pyyaml==6.0
Expand Down Expand Up @@ -124,6 +135,7 @@ types-urllib3==1.26.25.4
# via types-requests
typing-extensions==4.4.0
# via
# asgiref
# black
# django-filter-stubs
# django-stubs
Expand All @@ -134,6 +146,8 @@ typing-extensions==4.4.0
# platformdirs
urllib3==1.26.13
# via requests
watchdog==2.3.1
# via pytest-watch
wheel==0.38.4
# via pip-tools
zipp==3.11.0
Expand Down
22 changes: 22 additions & 0 deletions tests/test_filter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- case: filter_has_parent_property
main: |
from myapp.models import ProductFilter
name = ProductFilter().filters["name"]
reveal_type(name) # N: Revealed type is "django_filters.filters.Filter"
reveal_type(name.parent) # N: Revealed type is "django_filters.filterset.FilterSet"
files:
- path: myapp/__init__.py
- path: myapp/models.py
content: |
from django.db import models
import django_filters

class Product(models.Model):
name = models.CharField(max_length=255)

class ProductFilter(django_filters.FilterSet):
name = django_filters.CharFilter()

class Meta:
model = Product
fields = ['name']
Loading