Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ninja_jwt/tokens.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timedelta
from typing import Any, Optional, Tuple
from typing import Any, Optional, Tuple, TypeVar
from uuid import uuid4

from django.conf import settings
Expand All @@ -12,6 +12,8 @@
from .token_blacklist.models import BlacklistedToken, OutstandingToken
from .utils import aware_utcnow, datetime_from_epoch, datetime_to_epoch, format_lazy

T = TypeVar("T", bound="Token")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use typing.Self at first but it was only introduced in Python 3.11 and the testsuite checks against older Pythons.



class Token:
"""
Expand Down Expand Up @@ -181,7 +183,7 @@ def check_exp(self, claim: str = "exp", current_time: Optional[datetime] = None)
raise TokenError(format_lazy(_("Token '{}' claim has expired"), claim))

@classmethod
def for_user(cls, user: AbstractBaseUser) -> "Token":
def for_user(cls: T, user: AbstractBaseUser) -> T:
"""
Returns an authorization token for the given user that will be provided
after authenticating the user's credentials.
Expand Down Expand Up @@ -253,7 +255,7 @@ def blacklist(self) -> BlacklistedToken:
return BlacklistedToken.objects.get_or_create(token=token)

@classmethod
def for_user(cls, user: "AbstractBaseUser") -> Token:
def for_user(cls: T, user: "AbstractBaseUser") -> T:
"""
Adds this token to the outstanding token list.
"""
Expand Down