Skip to content

Commit

Permalink
Run pyupgrade on project
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrozdanic committed Jan 12, 2025
1 parent e979f52 commit e823603
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions rest_framework_simplejwt/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
if not isinstance(api_settings.AUTH_HEADER_TYPES, (list, tuple)):
AUTH_HEADER_TYPES = (AUTH_HEADER_TYPES,)

AUTH_HEADER_TYPE_BYTES: Set[bytes] = {
AUTH_HEADER_TYPE_BYTES: set[bytes] = {
h.encode(HTTP_HEADER_ENCODING) for h in AUTH_HEADER_TYPES
}

Expand All @@ -37,7 +37,7 @@ def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.user_model = get_user_model()

def authenticate(self, request: Request) -> Optional[Tuple[AuthUser, Token]]:
def authenticate(self, request: Request) -> Optional[tuple[AuthUser, Token]]:
header = self.get_header(request)
if header is None:
return None
Expand Down
6 changes: 3 additions & 3 deletions rest_framework_simplejwt/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
issuer: Optional[str] = None,
jwk_url: Optional[str] = None,
leeway: Union[float, int, timedelta, None] = None,
json_encoder: Optional[Type[json.JSONEncoder]] = None,
json_encoder: Optional[type[json.JSONEncoder]] = None,
) -> None:
self._validate_algorithm(algorithm)

Expand Down Expand Up @@ -110,7 +110,7 @@ def get_verifying_key(self, token: Token) -> Optional[str]:

return self.verifying_key

def encode(self, payload: Dict[str, Any]) -> str:
def encode(self, payload: dict[str, Any]) -> str:
"""
Returns an encoded token for the given payload dictionary.
"""
Expand All @@ -132,7 +132,7 @@ def encode(self, payload: Dict[str, Any]) -> str:
# For PyJWT >= 2.0.0a1
return token

def decode(self, token: Token, verify: bool = True) -> Dict[str, Any]:
def decode(self, token: Token, verify: bool = True) -> dict[str, Any]:
"""
Performs a validation of the given token and returns its payload
dictionary.
Expand Down
2 changes: 1 addition & 1 deletion rest_framework_simplejwt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DetailDictMixin:

def __init__(
self,
detail: Union[Dict[str, Any], str, None] = None,
detail: Union[dict[str, Any], str, None] = None,
code: Optional[str] = None,
) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion rest_framework_simplejwt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_all_permissions(self, obj: Optional[object] = None) -> set:
def has_perm(self, perm: str, obj: Optional[object] = None) -> bool:
return False

def has_perms(self, perm_list: List[str], obj: Optional[object] = None) -> bool:
def has_perms(self, perm_list: list[str], obj: Optional[object] = None) -> bool:
return False

def has_module_perms(self, module: str) -> bool:
Expand Down
16 changes: 8 additions & 8 deletions rest_framework_simplejwt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, *args, **kwargs) -> None:

class TokenObtainSerializer(serializers.Serializer):
username_field = get_user_model().USERNAME_FIELD
token_class: Optional[Type[Token]] = None
token_class: Optional[type[Token]] = None

default_error_messages = {
"no_active_account": _("No active account found with the given credentials")
Expand All @@ -41,7 +41,7 @@ def __init__(self, *args, **kwargs) -> None:
self.fields[self.username_field] = serializers.CharField(write_only=True)
self.fields["password"] = PasswordField()

def validate(self, attrs: Dict[str, Any]) -> Dict[Any, Any]:
def validate(self, attrs: dict[str, Any]) -> dict[Any, Any]:
authenticate_kwargs = {
self.username_field: attrs[self.username_field],
"password": attrs["password"],
Expand Down Expand Up @@ -69,7 +69,7 @@ def get_token(cls, user: AuthUser) -> Token:
class TokenObtainPairSerializer(TokenObtainSerializer):
token_class = RefreshToken

def validate(self, attrs: Dict[str, Any]) -> Dict[str, str]:
def validate(self, attrs: dict[str, Any]) -> dict[str, str]:
data = super().validate(attrs)

refresh = self.get_token(self.user)
Expand All @@ -86,7 +86,7 @@ def validate(self, attrs: Dict[str, Any]) -> Dict[str, str]:
class TokenObtainSlidingSerializer(TokenObtainSerializer):
token_class = SlidingToken

def validate(self, attrs: Dict[str, Any]) -> Dict[str, str]:
def validate(self, attrs: dict[str, Any]) -> dict[str, str]:
data = super().validate(attrs)

token = self.get_token(self.user)
Expand All @@ -108,7 +108,7 @@ class TokenRefreshSerializer(serializers.Serializer):
"no_active_account": _("No active account found for the given token.")
}

def validate(self, attrs: Dict[str, Any]) -> Dict[str, str]:
def validate(self, attrs: dict[str, Any]) -> dict[str, str]:
refresh = self.token_class(attrs["refresh"])

user_id = refresh.payload.get(api_settings.USER_ID_CLAIM, None)
Expand Down Expand Up @@ -148,7 +148,7 @@ class TokenRefreshSlidingSerializer(serializers.Serializer):
token = serializers.CharField()
token_class = SlidingToken

def validate(self, attrs: Dict[str, Any]) -> Dict[str, str]:
def validate(self, attrs: dict[str, Any]) -> dict[str, str]:
token = self.token_class(attrs["token"])

# Check that the timestamp in the "refresh_exp" claim has not
Expand All @@ -165,7 +165,7 @@ def validate(self, attrs: Dict[str, Any]) -> Dict[str, str]:
class TokenVerifySerializer(serializers.Serializer):
token = serializers.CharField(write_only=True)

def validate(self, attrs: Dict[str, None]) -> Dict[Any, Any]:
def validate(self, attrs: dict[str, None]) -> dict[Any, Any]:
token = UntypedToken(attrs["token"])

if (
Expand All @@ -183,7 +183,7 @@ class TokenBlacklistSerializer(serializers.Serializer):
refresh = serializers.CharField(write_only=True)
token_class = RefreshToken

def validate(self, attrs: Dict[str, Any]) -> Dict[Any, Any]:
def validate(self, attrs: dict[str, Any]) -> dict[Any, Any]:
refresh = self.token_class(attrs["refresh"])
try:
refresh.blacklist()
Expand Down
2 changes: 1 addition & 1 deletion rest_framework_simplejwt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@


class APISettings(_APISettings): # pragma: no cover
def __check_user_settings(self, user_settings: Dict[str, Any]) -> Dict[str, Any]:
def __check_user_settings(self, user_settings: dict[str, Any]) -> dict[str, Any]:
SETTINGS_DOC = "https://django-rest-framework-simplejwt.readthedocs.io/en/latest/settings.html"

for setting in REMOVED_SETTINGS:
Expand Down
2 changes: 1 addition & 1 deletion rest_framework_simplejwt/token_blacklist/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_queryset(self, *args, **kwargs) -> QuerySet:
# Read-only behavior defined below
actions = None

def get_readonly_fields(self, *args, **kwargs) -> List[Any]:
def get_readonly_fields(self, *args, **kwargs) -> list[Any]:
return [f.name for f in self.model._meta.fields]

def has_add_permission(self, *args, **kwargs) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions rest_framework_simplejwt/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def check_exp(
raise TokenError(format_lazy(_("Token '{}' claim has expired"), claim))

@classmethod
def for_user(cls: Type[T], user: AuthUser) -> T:
def for_user(cls: type[T], user: AuthUser) -> T:
"""
Returns an authorization token for the given user that will be provided
after authenticating the user's credentials.
Expand Down Expand Up @@ -246,7 +246,7 @@ class BlacklistMixin(Generic[T]):
membership in a token blacklist.
"""

payload: Dict[str, Any]
payload: dict[str, Any]

if "rest_framework_simplejwt.token_blacklist" in settings.INSTALLED_APPS:

Expand Down Expand Up @@ -288,7 +288,7 @@ def blacklist(self) -> BlacklistedToken:
return BlacklistedToken.objects.get_or_create(token=token)

@classmethod
def for_user(cls: Type[T], user: AuthUser) -> T:
def for_user(cls: type[T], user: AuthUser) -> T:
"""
Adds this token to the outstanding token list.
"""
Expand Down

0 comments on commit e823603

Please sign in to comment.