mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-15 08:17:08 +08:00
convince mypy that user.is_staff (and friends) are booleans (#542)
closes #512 Co-authored-by: proxi <51172302+3n-k1@users.noreply.github.com>
This commit is contained in:
@@ -13,3 +13,25 @@
|
||||
from django.test import Client
|
||||
|
||||
get_user(Client())
|
||||
- case: test_user_fields
|
||||
main: |
|
||||
from typing import Union
|
||||
from django.contrib.auth.models import AnonymousUser, User
|
||||
|
||||
anonymous: AnonymousUser
|
||||
anonymous_is_staff: bool = anonymous.is_staff
|
||||
anonymous_is_active: bool = anonymous.is_active
|
||||
anonymous_is_superuser: bool = anonymous.is_superuser
|
||||
anonymous_is_authenticated: bool = anonymous.is_authenticated
|
||||
|
||||
user: User
|
||||
user_is_staff: bool = user.is_staff
|
||||
user_is_active: bool = user.is_active
|
||||
user_is_superuser: bool = user.is_superuser
|
||||
user_is_authenticated: bool = user.is_authenticated
|
||||
|
||||
union: Union[User, AnonymousUser]
|
||||
union_is_staff: bool = union.is_staff
|
||||
union_is_active: bool = union.is_active
|
||||
union_is_superuser: bool = union.is_superuser
|
||||
union_is_authenticated: bool = union.is_authenticated
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
reveal_type(User().first_name) # N: Revealed type is 'builtins.str*'
|
||||
reveal_type(User().last_name) # N: Revealed type is 'builtins.str*'
|
||||
reveal_type(User().email) # N: Revealed type is 'builtins.str*'
|
||||
reveal_type(User().is_staff) # N: Revealed type is 'builtins.bool*'
|
||||
reveal_type(User().is_active) # N: Revealed type is 'builtins.bool*'
|
||||
reveal_type(User().is_staff) # N: Revealed type is 'builtins.bool'
|
||||
reveal_type(User().is_active) # N: Revealed type is 'builtins.bool'
|
||||
reveal_type(User().date_joined) # N: Revealed type is 'datetime.datetime*'
|
||||
reveal_type(User().last_login) # N: Revealed type is 'Union[datetime.datetime, None]'
|
||||
reveal_type(User().is_authenticated) # N: Revealed type is 'Literal[True]'
|
||||
@@ -22,7 +22,7 @@
|
||||
reveal_type(Permission().codename) # N: Revealed type is 'builtins.str*'
|
||||
|
||||
from django.contrib.auth.models import PermissionsMixin
|
||||
reveal_type(PermissionsMixin().is_superuser) # N: Revealed type is 'builtins.bool*'
|
||||
reveal_type(PermissionsMixin().is_superuser) # N: Revealed type is 'builtins.bool'
|
||||
|
||||
from django.contrib.auth.models import Group
|
||||
reveal_type(Group().name) # N: Revealed type is 'builtins.str*'
|
||||
|
||||
Reference in New Issue
Block a user