Run black on the repository, with the default configuration.
This commit is contained in:
@@ -24,12 +24,24 @@ DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Callable, Any, ClassVar, Dict, Iterator, Set, TYPE_CHECKING, Tuple, Type, TypeVar, Optional
|
||||
from typing import (
|
||||
Callable,
|
||||
Any,
|
||||
ClassVar,
|
||||
Dict,
|
||||
Iterator,
|
||||
Set,
|
||||
TYPE_CHECKING,
|
||||
Tuple,
|
||||
Type,
|
||||
TypeVar,
|
||||
Optional,
|
||||
)
|
||||
from .flags import BaseFlags, flag_value, fill_with_flags, alias_flag_value
|
||||
|
||||
__all__ = (
|
||||
'Permissions',
|
||||
'PermissionOverwrite',
|
||||
"Permissions",
|
||||
"PermissionOverwrite",
|
||||
)
|
||||
|
||||
# A permission alias works like a regular flag but is marked
|
||||
@@ -38,7 +50,9 @@ class permission_alias(alias_flag_value):
|
||||
alias: str
|
||||
|
||||
|
||||
def make_permission_alias(alias: str) -> Callable[[Callable[[Any], int]], permission_alias]:
|
||||
def make_permission_alias(
|
||||
alias: str,
|
||||
) -> Callable[[Callable[[Any], int]], permission_alias]:
|
||||
def decorator(func: Callable[[Any], int]) -> permission_alias:
|
||||
ret = permission_alias(func)
|
||||
ret.alias = alias
|
||||
@@ -46,7 +60,9 @@ def make_permission_alias(alias: str) -> Callable[[Callable[[Any], int]], permis
|
||||
|
||||
return decorator
|
||||
|
||||
P = TypeVar('P', bound='Permissions')
|
||||
|
||||
P = TypeVar("P", bound="Permissions")
|
||||
|
||||
|
||||
@fill_with_flags()
|
||||
class Permissions(BaseFlags):
|
||||
@@ -101,12 +117,14 @@ class Permissions(BaseFlags):
|
||||
|
||||
def __init__(self, permissions: int = 0, **kwargs: bool):
|
||||
if not isinstance(permissions, int):
|
||||
raise TypeError(f'Expected int parameter, received {permissions.__class__.__name__} instead.')
|
||||
raise TypeError(
|
||||
f"Expected int parameter, received {permissions.__class__.__name__} instead."
|
||||
)
|
||||
|
||||
self.value = permissions
|
||||
for key, value in kwargs.items():
|
||||
if key not in self.VALID_FLAGS:
|
||||
raise TypeError(f'{key!r} is not a valid permission name.')
|
||||
raise TypeError(f"{key!r} is not a valid permission name.")
|
||||
setattr(self, key, value)
|
||||
|
||||
def is_subset(self, other: Permissions) -> bool:
|
||||
@@ -114,14 +132,18 @@ class Permissions(BaseFlags):
|
||||
if isinstance(other, Permissions):
|
||||
return (self.value & other.value) == self.value
|
||||
else:
|
||||
raise TypeError(f"cannot compare {self.__class__.__name__} with {other.__class__.__name__}")
|
||||
raise TypeError(
|
||||
f"cannot compare {self.__class__.__name__} with {other.__class__.__name__}"
|
||||
)
|
||||
|
||||
def is_superset(self, other: Permissions) -> bool:
|
||||
"""Returns ``True`` if self has the same or more permissions as other."""
|
||||
if isinstance(other, Permissions):
|
||||
return (self.value | other.value) == self.value
|
||||
else:
|
||||
raise TypeError(f"cannot compare {self.__class__.__name__} with {other.__class__.__name__}")
|
||||
raise TypeError(
|
||||
f"cannot compare {self.__class__.__name__} with {other.__class__.__name__}"
|
||||
)
|
||||
|
||||
def is_strict_subset(self, other: Permissions) -> bool:
|
||||
"""Returns ``True`` if the permissions on other are a strict subset of those on self."""
|
||||
@@ -336,7 +358,7 @@ class Permissions(BaseFlags):
|
||||
""":class:`bool`: Returns ``True`` if a user can read messages from all or specific text channels."""
|
||||
return 1 << 10
|
||||
|
||||
@make_permission_alias('read_messages')
|
||||
@make_permission_alias("read_messages")
|
||||
def view_channel(self) -> int:
|
||||
""":class:`bool`: An alias for :attr:`read_messages`.
|
||||
|
||||
@@ -389,7 +411,7 @@ class Permissions(BaseFlags):
|
||||
""":class:`bool`: Returns ``True`` if a user can use emojis from other guilds."""
|
||||
return 1 << 18
|
||||
|
||||
@make_permission_alias('external_emojis')
|
||||
@make_permission_alias("external_emojis")
|
||||
def use_external_emojis(self) -> int:
|
||||
""":class:`bool`: An alias for :attr:`external_emojis`.
|
||||
|
||||
@@ -453,7 +475,7 @@ class Permissions(BaseFlags):
|
||||
"""
|
||||
return 1 << 28
|
||||
|
||||
@make_permission_alias('manage_roles')
|
||||
@make_permission_alias("manage_roles")
|
||||
def manage_permissions(self) -> int:
|
||||
""":class:`bool`: An alias for :attr:`manage_roles`.
|
||||
|
||||
@@ -471,7 +493,7 @@ class Permissions(BaseFlags):
|
||||
""":class:`bool`: Returns ``True`` if a user can create, edit, or delete emojis."""
|
||||
return 1 << 30
|
||||
|
||||
@make_permission_alias('manage_emojis')
|
||||
@make_permission_alias("manage_emojis")
|
||||
def manage_emojis_and_stickers(self) -> int:
|
||||
""":class:`bool`: An alias for :attr:`manage_emojis`.
|
||||
|
||||
@@ -535,7 +557,7 @@ class Permissions(BaseFlags):
|
||||
"""
|
||||
return 1 << 37
|
||||
|
||||
@make_permission_alias('external_stickers')
|
||||
@make_permission_alias("external_stickers")
|
||||
def use_external_stickers(self) -> int:
|
||||
""":class:`bool`: An alias for :attr:`external_stickers`.
|
||||
|
||||
@@ -551,7 +573,9 @@ class Permissions(BaseFlags):
|
||||
"""
|
||||
return 1 << 38
|
||||
|
||||
PO = TypeVar('PO', bound='PermissionOverwrite')
|
||||
|
||||
PO = TypeVar("PO", bound="PermissionOverwrite")
|
||||
|
||||
|
||||
def _augment_from_permissions(cls):
|
||||
cls.VALID_NAMES = set(Permissions.VALID_FLAGS)
|
||||
@@ -614,7 +638,7 @@ class PermissionOverwrite:
|
||||
Set the value of permissions by their name.
|
||||
"""
|
||||
|
||||
__slots__ = ('_values',)
|
||||
__slots__ = ("_values",)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
VALID_NAMES: ClassVar[Set[str]]
|
||||
@@ -670,7 +694,7 @@ class PermissionOverwrite:
|
||||
|
||||
for key, value in kwargs.items():
|
||||
if key not in self.VALID_NAMES:
|
||||
raise ValueError(f'no permission called {key}.')
|
||||
raise ValueError(f"no permission called {key}.")
|
||||
|
||||
setattr(self, key, value)
|
||||
|
||||
@@ -679,7 +703,9 @@ class PermissionOverwrite:
|
||||
|
||||
def _set(self, key: str, value: Optional[bool]) -> None:
|
||||
if value not in (True, None, False):
|
||||
raise TypeError(f'Expected bool or NoneType, received {value.__class__.__name__}')
|
||||
raise TypeError(
|
||||
f"Expected bool or NoneType, received {value.__class__.__name__}"
|
||||
)
|
||||
|
||||
if value is None:
|
||||
self._values.pop(key, None)
|
||||
|
||||
Reference in New Issue
Block a user