Bug report
What's wrong
I don't know how to annotate rest_framework.generics.GenericAPIView.filter_queryset. Before 3.16.9 we did this:
from typing import override
from django.db.models import QuerySet
from rest_framework import viewsets
from foo.models import MyModel
class MyModelViewSet(viewsets.ModelViewSet[MyModel]):
queryset = MyModel.objects.all()
filterset_fields = ('name',)
@override
def filter_queryset(self, queryset: QuerySet[MyModel]) -> QuerySet[MyModel]:
qs = super().filter_queryset(queryset)
return qs
But since 3.16.9 we get this error:
$ mypy .
/path/to/foo/views_rest.py:12: error: Return type "QuerySet[MyModel, MyModel]" of "filter_queryset" incompatible with return type "QuerySet[MyModel, _Row]" in supertype
"rest_framework.generics.GenericAPIView" [override]
def filter_queryset(self, queryset: QuerySet[MyModel]) -> QuerySet[MyModel]:
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path/to/foo/views_rest.py:12: error: Argument 1 of "filter_queryset" is incompatible with supertype "rest_framework.generics.GenericAPIView"; supertype defines the argument type as
"QuerySet[MyModel, _Row]" [override]
def filter_queryset(self, queryset: QuerySet[MyModel]) -> QuerySet[MyModel]:
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/path/to/foo/views_rest.py:12: note: This violates the Liskov substitution principle
/path/to/foo/views_rest.py:12: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
Found 2 errors in 1 file (checked 13 source files)
I assume that #916 is the cause.
How is that should be
There should be no error.
System information
- OS:
python version: 3.13.12
django version: 6.0.3
mypy version: 1.20.1
django-stubs version: 6.0.2
Bug report
What's wrong
I don't know how to annotate
rest_framework.generics.GenericAPIView.filter_queryset. Before 3.16.9 we did this:But since 3.16.9 we get this error:
I assume that #916 is the cause.
How is that should be
There should be no error.
System information
pythonversion: 3.13.12djangoversion: 6.0.3mypyversion: 1.20.1django-stubsversion: 6.0.2