From 6859ec94b6619c40cf0c033ab035f906503ffb45 Mon Sep 17 00:00:00 2001 From: Anthony Ricaud Date: Fri, 19 Jul 2019 12:42:03 +0100 Subject: [PATCH 1/2] More accurate `PermissionsMixin.has_perm` It only accepts `str` for `perm` --- django-stubs/contrib/auth/models.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django-stubs/contrib/auth/models.pyi b/django-stubs/contrib/auth/models.pyi index e539cb2..a8a91d9 100644 --- a/django-stubs/contrib/auth/models.pyi +++ b/django-stubs/contrib/auth/models.pyi @@ -41,7 +41,7 @@ class PermissionsMixin(models.Model): user_permissions: models.ManyToManyField = models.ManyToManyField(Permission) def get_group_permissions(self, obj: None = ...) -> Set[str]: ... def get_all_permissions(self, obj: Optional[str] = ...) -> Set[str]: ... - def has_perm(self, perm: Union[Tuple[str, Any], str], obj: Optional[str] = ...) -> bool: ... + def has_perm(self, perm: str, obj: Optional[str] = ...) -> bool: ... def has_perms(self, perm_list: Union[List[str], Set[str], Tuple[str]], obj: None = ...) -> bool: ... def has_module_perms(self, app_label: str) -> bool: ... From f365297baf3e18364c63adc697142ae12aa5f75c Mon Sep 17 00:00:00 2001 From: Anthony Ricaud Date: Sun, 21 Jul 2019 02:09:05 +0100 Subject: [PATCH 2/2] Allow any `Collection` to be passed to `has_perms` --- django-stubs/contrib/auth/models.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/django-stubs/contrib/auth/models.pyi b/django-stubs/contrib/auth/models.pyi index a8a91d9..b7c0f09 100644 --- a/django-stubs/contrib/auth/models.pyi +++ b/django-stubs/contrib/auth/models.pyi @@ -1,4 +1,4 @@ -from typing import Any, List, Optional, Set, Tuple, Type, Union +from typing import Any, Collection, Optional, Set, Tuple, Type, Union from django.contrib.auth.base_user import AbstractBaseUser as AbstractBaseUser, BaseUserManager as BaseUserManager from django.contrib.contenttypes.models import ContentType @@ -42,7 +42,7 @@ class PermissionsMixin(models.Model): def get_group_permissions(self, obj: None = ...) -> Set[str]: ... def get_all_permissions(self, obj: Optional[str] = ...) -> Set[str]: ... def has_perm(self, perm: str, obj: Optional[str] = ...) -> bool: ... - def has_perms(self, perm_list: Union[List[str], Set[str], Tuple[str]], obj: None = ...) -> bool: ... + def has_perms(self, perm_list: Collection[str], obj: None = ...) -> bool: ... def has_module_perms(self, app_label: str) -> bool: ... class AbstractUser(AbstractBaseUser, PermissionsMixin): # type: ignore @@ -80,7 +80,7 @@ class AnonymousUser: def get_group_permissions(self, obj: None = ...) -> Set[Any]: ... def get_all_permissions(self, obj: Any = ...) -> Set[str]: ... def has_perm(self, perm: str, obj: None = ...) -> bool: ... - def has_perms(self, perm_list: Union[List[str], Tuple[str]], obj: None = ...) -> bool: ... + def has_perms(self, perm_list: Collection[str], obj: None = ...) -> bool: ... def has_module_perms(self, module: str) -> bool: ... @property def is_anonymous(self) -> bool: ...