You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm following along with the quickstart guide for the Django REST framework and I have the following snippet of code:
fromdjango.contrib.auth.modelsimportGroup, Userfromrest_frameworkimportpermissions, viewsetsfromxxx.schemas.serializersimportGroupSerializer, UserSerializerclassUserViewSet(viewsets.ModelViewSet):
""" API endpoint that allows users to be viewed or edited. """queryset=User.objects.all().order_by("-date_joined")
serializer_class=UserSerializerpermission_classes= [permissions.IsAuthenticated]
When I run mypy --strict . it complains:
src/xxx/schemas/views.py:7: error: Missing type parameters for generic type "ModelViewSet" [type-arg]
If I change the line to
classUserViewSet(viewsets.ModelViewSet[User]):
then mypy is happy, but I am no longer able to run my application:
TypeError: type 'ModelViewSet' is not subscriptable
How is that should be
How do I write my code such that both mypy and Python are happy?
System information
OS:
python version: Ubuntu 22.0.4.2 LTS
django version: 4.1.7
mypy version: 1.0.1
django-stubs version: 1.15.0
djangorestframework-stubs version: 1.9.1
The text was updated successfully, but these errors were encountered:
Bug report
What's wrong
I'm following along with the quickstart guide for the Django REST framework and I have the following snippet of code:
When I run
mypy --strict .
it complains:If I change the line to
then mypy is happy, but I am no longer able to run my application:
How is that should be
How do I write my code such that both mypy and Python are happy?
System information
python
version: Ubuntu 22.0.4.2 LTSdjango
version: 4.1.7mypy
version: 1.0.1django-stubs
version: 1.15.0djangorestframework-stubs
version: 1.9.1The text was updated successfully, but these errors were encountered: