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

Incorrect typing for refresh token. #821

Open
proofit404 opened this issue Aug 16, 2024 · 2 comments
Open

Incorrect typing for refresh token. #821

proofit404 opened this issue Aug 16, 2024 · 2 comments

Comments

@proofit404
Copy link

Let say we have code block like this:

def create_token(profile_id: ProfileId) -> Token:
    user = User.objects.get(profiletable=profile_id)
    refresh = RefreshToken.for_user(user)
    return str(refresh.access_token)

That would produce error in mypy:

venv/lib/python3.12/site-packages/web/repositories/token.py: note: In function "create_token":
venv/lib/python3.12/site-packages/web/repositories/token.py:13:16: error: "Token" has no attribute "access_token" 
[attr-defined]
        return str(refresh.access_token)
                   ^~~~~~~~~~~~~~~~~~~~

Token.for_user class method returns cls() which allows subclasses returns it's own instances. But annotations says it would always be a Token.

Maybe typing.Self would work?

@sterliakov
Copy link
Contributor

This should be resolved after #776 (not released yet) - please try the master branch version to confirm.

@sterliakov
Copy link
Contributor

And duplicates #794.

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

No branches or pull requests

2 participants