Skip to content

When overriding APIView.get_permissions, mypy complains about return type incompatebility #319

@guldfisk

Description

@guldfisk

In this example:

from rest_framework.viewsets import GenericViewSet
from rest_framework.permissions import BasePermission


class MyView(GenericViewSet):
    def get_permissions(self) -> list[BasePermission]:
        ...

Mypy generates the following error:

example.py:6: error: Return type "List[BasePermission]" of "get_permissions" incompatible with return type "List[_SupportsHasPermission]" in supertype "APIView"  [override]

Even though BasePermission implements _SupportsHasPermission

System information

  • OS:
  • python version: 3.10
  • django version: 4.1
  • mypy version: 0.991
  • django-stubs version: 1.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions