Skip to content

Conversation

@khvn26
Copy link

@khvn26 khvn26 commented Mar 13, 2025

  • Resorted to using virtual subclassing instead of a current TypeVar for the AuthToken/AbstractBaseUser covariant type as it doesn't seem to play nice with Mypy.
  • Added virtual subclassing to the mixin. Current Generic usage seems plain wrong.
  • Added if TYPE_CHECKING: assert self.user assertions to TokenObtainSerializer implementations to make Mypy understand the serializer lifecycle.
  • Added type-checking assertion for lifetime in Token.set_exp.
  • Other minor improvements.

@khvn26 khvn26 changed the title fix: Various typing improvements feat: Various typing improvements Mar 13, 2025
@vgrozdanic
Copy link
Contributor

Thank you for your contribution!

I see that a lot of tests are failing, python 3.9 which we still support doesn't have some of the typing attributes available (e.g. TypeAlias).

Can you please make this PR compatible with python versions 3.9 - 3.13?



class TokenUser:
class TokenUser(TokenUserBase):
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this being introduced?

Is there a reason why TokenUser should be a subclass of AbstractBaseUser?

Copy link
Member

Choose a reason for hiding this comment

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

I have a feeling it's because, unlike Typescript, there isn't interface overlapping in Python, so the author was trying to resolve what happens when you receive a "user" type.

They made a change here that explains it a little:

Suggested change
class TokenUser(TokenUserBase):
- AuthUser = TypeVar("AuthUser", AbstractBaseUser, TokenUser)
+ TokenTypeVar = TypeVar("TokenTypeVar", bound=Token)

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

Successfully merging this pull request may close these issues.

3 participants