We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have defined a BaseModelViewSet
from abc import ABCMeta, abstractmethod from http import HTTPMethod from django.db.models import QuerySet from rest_framework.decorators import action from rest_framework.request import Request from rest_framework.response import Response from rest_framework.serializers import ModelSerializer from rest_framework.viewsets import ModelViewSet from my_app.models import SomeBaseModel class BaseModelViewSet[_M: SomeBaseModel](ModelViewSet[_M], metaclass=ABCMeta): queryset: QuerySet[_M] serializer_class: type[ModelSerializer[_M]] @abstractmethod @action(detail=False, methods=[HTTPMethod.GET]) def some_action(self, request: Request) -> Response: raise NotImplementedError
And a child view set
from my_app.models import ConcreteModel from my_app.serializers import ConcreteModelSerializer class ConcreteModelViewSet(BaseModelViewSet[ConcreteModel]): queryset = ConcreteModel.objects.all() serializer_class = ConcreteModelSerializer @override @action(detail=False, methods=[HTTPMethod.GET]) def some_action(self, request: Request) -> Response: return Response({})
I get the error
my_app/view_rest.py:316: error: Signature of "some_action" incompatible with supertype "BaseModelViewSet" [override] def some_action(self, request: Request) -> Response: ^ my_app/view_rest.py:316: note: Superclass: my_app/view_rest.py:316: note: ViewSetAction[Callable[[BaseModelViewSet[_M], Request], Response]] my_app/view_rest.py:316: note: Subclass: my_app/view_rest.py:316: note: ViewSetAction[Callable[[ConcreteModelViewSet, Request], Response]]
If I remove the @action decorator mypy passes.
@action
Mypy should pass
python
django
mypy
django-stubs
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug report
What's wrong
I have defined a BaseModelViewSet
And a child view set
I get the error
If I remove the
@action
decorator mypy passes.How is that should be
Mypy should pass
System information
python
version: 3.12.7django
version: 5.1.1mypy
version: 1.14.1django-stubs
version: 5.1.2The text was updated successfully, but these errors were encountered: