Add djangorestframework-stubs

Add djangorestframework-stubs to local.txt requirements
Modify setup.cfg to add stubs to mypy settings
Fix new type error in DRF

`./users/api/views.py:19: error: Incompatible type for lookup 'id': (got "Union[AutoField[Union[Combinable, int, str], int], Any]", expected "Union[str, int]")`

by asserting that `self.request.user.id` is an int
This commit is contained in:
Dalton Rardin 2021-10-09 01:09:46 -05:00
parent c1484361a7
commit 00ff825b8c
No known key found for this signature in database
GPG Key ID: D315D829E1C20E7F
3 changed files with 5 additions and 1 deletions

View File

@ -17,6 +17,9 @@ mypy==0.910 # https://github.com/python/mypy
django-stubs==1.8.0 # https://github.com/typeddjango/django-stubs
pytest==6.2.5 # https://github.com/pytest-dev/pytest
pytest-sugar==0.9.4 # https://github.com/Frozenball/pytest-sugar
{%- if cookiecutter.use_drf == "y" %}
djangorestframework-stubs==1.4.0 # https://github.com/typeddjango/djangorestframework-stubs
{%- endif %}
# Documentation
# ------------------------------------------------------------------------------

View File

@ -24,7 +24,7 @@ ignore_missing_imports = True
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True
plugins = mypy_django_plugin.main
plugins = mypy_django_plugin.main{% if cookiecutter.use_drf == "y" %}, mypy_drf_plugin.main{% endif %}
[mypy.plugins.django-stubs]
django_settings_module = config.settings.test

View File

@ -16,6 +16,7 @@ class UserViewSet(RetrieveModelMixin, ListModelMixin, UpdateModelMixin, GenericV
lookup_field = "username"
def get_queryset(self, *args, **kwargs):
assert isinstance(self.request.user.id, int)
return self.queryset.filter(id=self.request.user.id)
@action(detail=False, methods=["GET"])