Skip to content

Commit d8bee67

Browse files
committed
support more cases
1 parent 5977c99 commit d8bee67

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Diff for: rest_framework-stubs/permissions.pyi

+1-1
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(_SupportsHasPermission):
19+
class OperationHolderMixin:
2020
def __and__(self, other: _PermissionClass) -> OperandHolder: ...
2121
def __or__(self, other: _PermissionClass) -> OperandHolder: ...
2222
def __rand__(self, other: _PermissionClass) -> OperandHolder: ...

Diff for: rest_framework-stubs/views.pyi

+1-1
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) -> list[_SupportsHasPermission]: ...
74+
def get_permissions(self) -> Sequence[_SupportsHasPermission]: ...
7575
def get_throttles(self) -> list[BaseThrottle]: ...
7676
def get_content_negotiator(self) -> BaseContentNegotiation: ...
7777
def get_exception_handler(self) -> Callable: ...

Diff for: tests/typecheck/test_views.yml

+14-3
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,31 @@
6969
main: |
7070
from typing import List
7171
72+
from rest_framework.viewsets import GenericViewSet
73+
from rest_framework.permissions import BasePermission, IsAdminUser
74+
75+
class MyView(GenericViewSet):
76+
def get_permissions(self) -> List[BasePermission]:
77+
...
78+
79+
- case: test_override_get_permissions_super
80+
main: |
81+
from typing import Sequence
82+
7283
from rest_framework.viewsets import GenericViewSet
7384
from rest_framework.permissions import _SupportsHasPermission
7485
7586
class MyView(GenericViewSet):
76-
def get_permissions(self) -> List[_SupportsHasPermission]:
87+
def get_permissions(self) -> Sequence[_SupportsHasPermission]:
7788
return super().get_permissions()
7889
7990
- case: test_override_get_permissions_operandholder
8091
main: |
8192
from typing import Sequence
8293
8394
from rest_framework.viewsets import GenericViewSet
84-
from rest_framework.permissions import BasePermission, IsAuthenticated, IsAdminUser, _SupportsHasPermission
95+
from rest_framework.permissions import AND, IsAuthenticated, IsAdminUser, _SupportsHasPermission
8596
8697
class MyView(GenericViewSet):
8798
def get_permissions(self) -> list[_SupportsHasPermission]:
88-
return [IsAuthenticated & IsAdminUser]
99+
return [AND(IsAuthenticated(), IsAdminUser())]

0 commit comments

Comments
 (0)