Skip to content

Commit bd3ca3c

Browse files
authored
correct bound for _UserType (#2645)
1 parent 2ded950 commit bd3ca3c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

django-stubs/contrib/auth/models.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ _AnyUser: TypeAlias = _User | AnonymousUser
2424
# These are only needed for generic classes in order to bind to a specific implementation
2525
_AnyUserType = TypeVar("_AnyUserType", bound=_AnyUser) # noqa: PYI018
2626

27-
# do not use the alias `_User` so the bound remains at `AbstractUser`
28-
_UserType = TypeVar("_UserType", bound=AbstractUser)
27+
# do not use the alias `_User` so the bound remains at `AbstractBaseUser`
28+
_UserType = TypeVar("_UserType", bound=AbstractBaseUser)
2929

3030
def update_last_login(sender: _UserModel, user: _User, **kwargs: Any) -> None: ...
3131

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.contrib.auth.models import AbstractBaseUser, UserManager
2+
from typing_extensions import assert_type
3+
4+
5+
class MyUser(AbstractBaseUser):
6+
pass
7+
8+
9+
class Manager(UserManager[MyUser]):
10+
pass
11+
12+
13+
assert_type(Manager().create_user("username"), MyUser)

0 commit comments

Comments
 (0)