diff options
| author | Rapptz <[email protected]> | 2021-04-04 04:40:19 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-04-04 07:03:53 -0400 |
| commit | 9d39b135f4f84239787b0901d06a4f370a82d4bb (patch) | |
| tree | 8826845cfd47eafa5c9d2ef1fcbedd36382714f4 /discord/permissions.py | |
| parent | Bump minimum Python version to 3.8 (diff) | |
| download | discord.py-9d39b135f4f84239787b0901d06a4f370a82d4bb.tar.xz discord.py-9d39b135f4f84239787b0901d06a4f370a82d4bb.zip | |
Modernize code to use f-strings
This also removes the encoding on the top, since Python 3 does it by
default. It also changes some methods to use `yield from`.
Diffstat (limited to 'discord/permissions.py')
| -rw-r--r-- | discord/permissions.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/discord/permissions.py b/discord/permissions.py index 3fd0dacf..fe6cabf5 100644 --- a/discord/permissions.py +++ b/discord/permissions.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ The MIT License (MIT) @@ -96,12 +94,12 @@ class Permissions(BaseFlags): def __init__(self, permissions=0, **kwargs): if not isinstance(permissions, int): - raise TypeError('Expected int parameter, received %s instead.' % permissions.__class__.__name__) + 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('%r is not a valid permission name.' % key) + raise TypeError(f'{key!r} is not a valid permission name.') setattr(self, key, value) def is_subset(self, other): @@ -109,14 +107,14 @@ class Permissions(BaseFlags): if isinstance(other, Permissions): return (self.value & other.value) == self.value else: - raise TypeError("cannot compare {} with {}".format(self.__class__.__name__, other.__class__.__name__)) + raise TypeError(f"cannot compare {self.__class__.__name__} with {other.__class__.__name__}") def is_superset(self, other): """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("cannot compare {} with {}".format(self.__class__.__name__, other.__class__.__name__)) + raise TypeError(f"cannot compare {self.__class__.__name__} with {other.__class__.__name__}") def is_strict_subset(self, other): """Returns ``True`` if the permissions on other are a strict subset of those on self.""" @@ -539,7 +537,7 @@ class PermissionOverwrite: for key, value in kwargs.items(): if key not in self.VALID_NAMES: - raise ValueError('no permission called {0}.'.format(key)) + raise ValueError(f'no permission called {key}.') setattr(self, key, value) @@ -548,7 +546,7 @@ class PermissionOverwrite: def _set(self, key, value): if value not in (True, None, False): - raise TypeError('Expected bool or NoneType, received {0.__class__.__name__}'.format(value)) + raise TypeError(f'Expected bool or NoneType, received {value.__class__.__name__}') if value is None: self._values.pop(key, None) |