Skip to content

Commit

Permalink
support more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mschoettle committed Oct 23, 2023
1 parent 5977c99 commit 60422fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rest_framework-stubs/permissions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class _SupportsHasPermission(Protocol):
# https://github.com/python/mypy/issues/12392
_PermissionClass: TypeAlias = type[BasePermission] | OperandHolder | SingleOperandHolder

class OperationHolderMixin(_SupportsHasPermission):
class OperationHolderMixin:
def __and__(self, other: _PermissionClass) -> OperandHolder: ...
def __or__(self, other: _PermissionClass) -> OperandHolder: ...
def __rand__(self, other: _PermissionClass) -> OperandHolder: ...
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/views.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class APIView(View):
def get_renderers(self) -> list[BaseRenderer]: ...
def get_parsers(self) -> list[BaseParser]: ...
def get_authenticators(self) -> list[BaseAuthentication]: ...
def get_permissions(self) -> list[_SupportsHasPermission]: ...
def get_permissions(self) -> Sequence[_SupportsHasPermission]: ...
def get_throttles(self) -> list[BaseThrottle]: ...
def get_content_negotiator(self) -> BaseContentNegotiation: ...
def get_exception_handler(self) -> Callable: ...
Expand Down
17 changes: 14 additions & 3 deletions tests/typecheck/test_views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,31 @@
main: |
from typing import List
from rest_framework.viewsets import GenericViewSet
from rest_framework.permissions import BasePermission, IsAdminUser
class MyView(GenericViewSet):
def get_permissions(self) -> List[BasePermission]:
return [IsAdminUser()]
- case: test_override_get_permissions_super
main: |
from typing import Sequence
from rest_framework.viewsets import GenericViewSet
from rest_framework.permissions import _SupportsHasPermission
class MyView(GenericViewSet):
def get_permissions(self) -> List[_SupportsHasPermission]:
def get_permissions(self) -> Sequence[_SupportsHasPermission]:
return super().get_permissions()
- case: test_override_get_permissions_operandholder
main: |
from typing import Sequence
from rest_framework.viewsets import GenericViewSet
from rest_framework.permissions import BasePermission, IsAuthenticated, IsAdminUser, _SupportsHasPermission
from rest_framework.permissions import AND, IsAuthenticated, IsAdminUser, _SupportsHasPermission
class MyView(GenericViewSet):
def get_permissions(self) -> list[_SupportsHasPermission]:
return [IsAuthenticated & IsAdminUser]
return [AND(IsAuthenticated(), IsAdminUser())]

0 comments on commit 60422fb

Please sign in to comment.