Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token subclass' for_user method is typed to return a Token #794

Open
Samuel-Therrien-Beslogic opened this issue Apr 3, 2024 · 0 comments
Labels

Comments

@Samuel-Therrien-Beslogic

The example from the doc itself is a good minimal reproduction of this issue:

https://django-rest-framework-simplejwt.readthedocs.io/en/latest/creating_tokens_manually.html

from django.contrib.auth.models import AbstractBaseUser
from rest_framework_simplejwt.tokens import RefreshToken


def get_tokens_for_user(user: AbstractBaseUser):
    refresh = RefreshToken.for_user(user)

    return {
        "refresh": str(refresh),
        "access": str(refresh.access_token),  # "Token" has no attribute "access_token" Mypy [attr-defined]
    }

RefreshToken.for_user(user)'s return type, as seen by type-checkers (mypy/pyright) is Token instead of RefreshToken.

This is caused by BlacklistMixin.for_user being typed to return a Token, where I believe it should probably return Self (from typing_extensions import Self)

CC @theo-auffeuvre & @NicolasDontigny for visibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants