|
| 1 | +from typing import Sequence, Type, TYPE_CHECKING |
| 2 | + |
1 | 3 | from importlib import import_module
|
2 | 4 |
|
3 | 5 | from django.conf import settings
|
4 | 6 |
|
5 | 7 | from django.contrib import auth
|
6 | 8 |
|
7 |
| -from rest_framework.permissions import IsAuthenticated |
| 9 | +from rest_framework.permissions import IsAuthenticated, BasePermission |
8 | 10 | from rest_framework.authentication import SessionAuthentication, BaseAuthentication
|
9 | 11 |
|
10 | 12 | from rest_framework_jwt.authentication import JSONWebTokenAuthentication
|
@@ -60,10 +62,20 @@ def enforce_csrf(self, request):
|
60 | 62 | return
|
61 | 63 |
|
62 | 64 |
|
| 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 | + |
63 | 75 | class ApiAuthMixin:
|
64 |
| - authentication_classes = ( |
| 76 | + authentication_classes: Sequence[Type[BaseAuthentication]] = [ |
65 | 77 | CsrfExemptedSessionAuthentication,
|
66 | 78 | SessionAsHeaderAuthentication,
|
67 | 79 | JSONWebTokenAuthentication
|
68 |
| - ) |
69 |
| - permission_classes = (IsAuthenticated, ) |
| 80 | + ] |
| 81 | + permission_classes: PermissionClassesType = (IsAuthenticated, ) |
0 commit comments