Skip to content

Commit 5977c99

Browse files
committed
fix: return list instead of sequence
1 parent 3a0197a commit 5977c99

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

rest_framework-stubs/permissions.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class _SupportsHasPermission(Protocol):
1616
# https://github.com/python/mypy/issues/12392
1717
_PermissionClass: TypeAlias = type[BasePermission] | OperandHolder | SingleOperandHolder
1818

19-
class OperationHolderMixin:
19+
class OperationHolderMixin(_SupportsHasPermission):
2020
def __and__(self, other: _PermissionClass) -> OperandHolder: ...
2121
def __or__(self, other: _PermissionClass) -> OperandHolder: ...
2222
def __rand__(self, other: _PermissionClass) -> OperandHolder: ...

rest_framework-stubs/views.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class APIView(View):
7171
def get_renderers(self) -> list[BaseRenderer]: ...
7272
def get_parsers(self) -> list[BaseParser]: ...
7373
def get_authenticators(self) -> list[BaseAuthentication]: ...
74-
def get_permissions(self) -> Sequence[_SupportsHasPermission]: ...
74+
def get_permissions(self) -> list[_SupportsHasPermission]: ...
7575
def get_throttles(self) -> list[BaseThrottle]: ...
7676
def get_content_negotiator(self) -> BaseContentNegotiation: ...
7777
def get_exception_handler(self) -> Callable: ...

tests/typecheck/test_views.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,19 @@
7070
from typing import List
7171
7272
from rest_framework.viewsets import GenericViewSet
73-
from rest_framework.permissions import BasePermission
73+
from rest_framework.permissions import _SupportsHasPermission
7474
7575
class MyView(GenericViewSet):
76-
def get_permissions(self) -> List[BasePermission]:
77-
...
76+
def get_permissions(self) -> List[_SupportsHasPermission]:
77+
return super().get_permissions()
78+
79+
- case: test_override_get_permissions_operandholder
80+
main: |
81+
from typing import Sequence
82+
83+
from rest_framework.viewsets import GenericViewSet
84+
from rest_framework.permissions import BasePermission, IsAuthenticated, IsAdminUser, _SupportsHasPermission
85+
86+
class MyView(GenericViewSet):
87+
def get_permissions(self) -> list[_SupportsHasPermission]:
88+
return [IsAuthenticated & IsAdminUser]

0 commit comments

Comments
 (0)