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

Resolve configured AUTH_USER_MODEL with a get_type_analyze_hook #2335

Merged
merged 8 commits into from
Aug 12, 2024
Prev Previous commit
Next Next commit
fixup! fixup! fixup! Resolve configured AUTH_USER_MODEL with a `get…
…_type_analyze_hook`
flaeppe committed Aug 10, 2024
commit a926dc6e9c014e093d7dcf65f6d7a890ef3528ad
12 changes: 6 additions & 6 deletions django-stubs/contrib/auth/backends.pyi
Original file line number Diff line number Diff line change
@@ -7,12 +7,12 @@ from django.db.models.base import Model
from django.http.request import HttpRequest
from typing_extensions import TypeAlias

UserModel: TypeAlias = _UserModel
_AnyUser: TypeAlias = UserModel | AnonymousUser
UserModel: TypeAlias = type[_UserModel]
_AnyUser: TypeAlias = _UserModel | AnonymousUser

class BaseBackend:
def authenticate(self, request: HttpRequest | None, **kwargs: Any) -> UserModel | None: ...
def get_user(self, user_id: Any) -> UserModel | None: ...
def authenticate(self, request: HttpRequest | None, **kwargs: Any) -> _UserModel | None: ...
def get_user(self, user_id: Any) -> _UserModel | None: ...
def get_user_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ...
def get_group_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ...
def get_all_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ...
@@ -21,7 +21,7 @@ class BaseBackend:
class ModelBackend(BaseBackend):
def authenticate(
self, request: HttpRequest | None, username: str | None = ..., password: str | None = ..., **kwargs: Any
) -> UserModel | None: ...
) -> _UserModel | None: ...
def has_module_perms(self, user_obj: _AnyUser, app_label: str) -> bool: ...
def user_can_authenticate(self, user: _AnyUser | None) -> bool: ...
def with_perm(
@@ -30,7 +30,7 @@ class ModelBackend(BaseBackend):
is_active: bool = ...,
include_superusers: bool = ...,
obj: Model | None = ...,
) -> QuerySet[UserModel]: ...
) -> QuerySet[_UserModel]: ...

class AllowAllUsersModelBackend(ModelBackend): ...

3 changes: 2 additions & 1 deletion django-stubs/contrib/auth/forms.pyi
Original file line number Diff line number Diff line change
@@ -10,8 +10,9 @@ from django.db.models.fields import _ErrorMessagesDict
from django.forms.fields import _ClassLevelWidgetT
from django.forms.widgets import Widget
from django.http.request import HttpRequest
from typing_extensions import TypeAlias

UserModel: type[_UserModel]
UserModel: TypeAlias = type[_UserModel]
_User = TypeVar("_User", bound=AbstractBaseUser)

class ReadOnlyPasswordHashWidget(forms.Widget):
3 changes: 2 additions & 1 deletion django-stubs/contrib/auth/views.pyi
Original file line number Diff line number Diff line change
@@ -6,8 +6,9 @@ from django.http.request import HttpRequest
from django.http.response import HttpResponse, HttpResponseRedirect
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView
from typing_extensions import TypeAlias

UserModel: type[_UserModel]
UserModel: TypeAlias = type[_UserModel]

class RedirectURLMixin:
next_page: str | None