-
-
Notifications
You must be signed in to change notification settings - Fork 454
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
create and re-use TypeAlias
es and TypeVar
s for "user" and "any user"
#2384
base: master
Are you sure you want to change the base?
create and re-use TypeAlias
es and TypeVar
s for "user" and "any user"
#2384
Conversation
08131cc
to
513df00
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally - looks great! Just one note
django-stubs/contrib/auth/models.pyi
Outdated
# This is our "placeholder" type the mypy plugin refines to configured 'AUTH_USER_MODEL' | ||
# wherever it is used as a type. The most recognised example of this is (probably) | ||
# `HttpRequest.user` | ||
_User: TypeAlias = AbstractUser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this before _AnyUser
, no need to create an extra inference cycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should change the base class to be AbstractUser
. This is a section of what the "Specifying a custom user model" says in the docs:
[...] The easiest way to construct a compliant custom user model is to inherit from AbstractBaseUser. AbstractBaseUser provides the core implementation of a user model, including hashed passwords and tokenized password resets. [...]
https://docs.djangoproject.com/en/5.1/topics/auth/customizing/#specifying-a-custom-user-model
As far as I understand, this is not the base class, this is the default type, unless |
That's interesting that they suggest that... The issue is that It does look like there's probably some complications if we move the base class up (subclasses of |
…liases This change updates the previous ``AUTH_USER_MODEL`` placeholder alias to default to ``AbstractUser`` instead of ``AbstractBaseUser`` which does not include the ``PermissionsMixin``, so that the type alias works better even without the mypy plugin. This change also adds a few user type vars and alises to cover the common use cases of ``User``, ``User | AnonymousUser``, and their ``TypeVar`` forms for using in generic contexts.
513df00
to
06a4f41
Compare
I rolled back the change since it does affect a user who subclasses This change still adds some helpful aliases so it can get merged in and the follow-up can be done independently. |
AUTH_USER_MODEL
to be AbstractUser
and reuse aliasesTypeAlias
es and TypeVar
s for User and AnyUser
TypeAlias
es and TypeVar
s for User and AnyUserTypeAlias
es and TypeVar
s for "user" and "any user"
I have made things!
This change also adds a few user type vars and alises to cover the common use cases of
User
,User | AnonymousUser
, and theirTypeVar
forms for using in generic contexts.