Skip to content

Commit

Permalink
Add type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jerivas committed Nov 22, 2022
1 parent 9dfcf0c commit 58cd064
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
7 changes: 6 additions & 1 deletion filter_bug_repro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

from pathlib import Path

import django_stubs_ext
from rest_framework import viewsets

django_stubs_ext.monkeypatch(extra_classes=(viewsets.ModelViewSet,))

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand All @@ -25,7 +30,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS: list[str] = []


# Application definition
Expand Down
8 changes: 4 additions & 4 deletions filter_bug_repro/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ class Document(models.Model):
name = models.CharField(max_length=255)
owner = models.ForeignKey("auth.User", on_delete=models.CASCADE)

def __str__(self):
def __str__(self) -> str:
return self.name


class DocumentFilterSet(filters.FilterSet):
class DocumentFilterSet(filters.FilterSet): # type: ignore
class Meta:
model = Document
fields = ("owner",)


class DocumentSerializer(serializers.ModelSerializer):
class DocumentSerializer(serializers.ModelSerializer[Document]):
class Meta:
model = Document
fields = ("id", "name", "owner")


class DocumentViewSet(viewsets.ModelViewSet):
class DocumentViewSet(viewsets.ModelViewSet[Document]):
queryset = Document.objects.all()
serializer_class = DocumentSerializer
filterset_class = DocumentFilterSet
Expand Down
28 changes: 28 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[mypy]
python_version = 3.10

warn_return_any = True
warn_unused_configs = True
warn_unused_ignores = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
disallow_untyped_decorators = True
disallow_any_expr = False
disallow_any_decorated = True
disallow_subclassing_any = True
disallow_any_generics = True
disallow_any_explicit = False
disallow_any_unimported = True
no_implicit_optional = True
strict_equality = True
warn_redundant_casts = True

plugins =
mypy_django_plugin.main,
mypy_drf_plugin.main

[mypy.plugins.django-stubs]
django_settings_module = filter_bug_repro.settings

[mypy-django_filters.*]
ignore_missing_imports = True

0 comments on commit 58cd064

Please sign in to comment.