Skip to content

Commit 8f4ddf0

Browse files
committed
Type-check ApiAuthMixin
1 parent 0f95fb2 commit 8f4ddf0

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

styleguide_example/api/mixins.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
from typing import Sequence, Type, TYPE_CHECKING
2+
13
from importlib import import_module
24

35
from django.conf import settings
46

57
from django.contrib import auth
68

7-
from rest_framework.permissions import IsAuthenticated
9+
from rest_framework.permissions import IsAuthenticated, BasePermission
810
from rest_framework.authentication import SessionAuthentication, BaseAuthentication
911

1012
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
@@ -60,10 +62,20 @@ def enforce_csrf(self, request):
6062
return
6163

6264

65+
if TYPE_CHECKING:
66+
# This is going to be resolved in the stub library
67+
# https://github.com/typeddjango/djangorestframework-stubs/
68+
from rest_framework.permissions import _PermissionClass
69+
70+
PermissionClassesType = Sequence[_PermissionClass]
71+
else:
72+
PermissionClassesType = Sequence[Type[BasePermission]]
73+
74+
6375
class ApiAuthMixin:
64-
authentication_classes = (
76+
authentication_classes: Sequence[Type[BaseAuthentication]] = [
6577
CsrfExemptedSessionAuthentication,
6678
SessionAsHeaderAuthentication,
6779
JSONWebTokenAuthentication
68-
)
69-
permission_classes = (IsAuthenticated, )
80+
]
81+
permission_classes: PermissionClassesType = (IsAuthenticated, )

0 commit comments

Comments
 (0)