mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-07 10:22:59 +00:00
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`.
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user