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

[FR] Make django.contrib.auth.base_user._UserModel part of a public API #2366

Open
sterliakov opened this issue Sep 10, 2024 · 1 comment
Open

Comments

@sterliakov
Copy link
Contributor

Introduced in #2335, _UserModel type alias is resolved by plugin to point to current AUTH_USER_MODEL.

This functionality is extremely helpful in certain circumstances, esp. when typing django-related packages. I was trying to improve type hints of djangorestframework-simplejwt and noticed that it'd be very convenient to use this _UserModel alias to spell "type of current user model".

For example, this will help me annotate the authentication class correctly: it calls get_user_model internally, assigning returned class to an instance variable. Annotating with _UserModel would greatly improve usability compared to AbstractBaseUser.

I propose to add an alias to django_stubs_ext resolved in the same way as _UserModel.

I'm willing to open a PR with this change if that sounds reasonable.

@sterliakov sterliakov changed the title [FR] Make _django.contrib.auth.base_user._UserModel part of a public API [FR] Make django.contrib.auth.base_user._UserModel part of a public API Sep 10, 2024
@flaeppe
Copy link
Member

flaeppe commented Sep 11, 2024

Yes I agree, we should make it public. Having _UserModel public should be very helpful for 3rd party code.

We've previously mentioned this in: typeddjango/djangorestframework-stubs#650 (comment) and typeddjango/djangorestframework-stubs#651 (review)

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

No branches or pull requests

2 participants