Browse Source

Slightly improve performance of constructing Permissions using kwargs

pull/9553/head
Rapptz 2 years ago
parent
commit
b6794fa6d1
  1. 14
      discord/permissions.py

14
discord/permissions.py

@ -141,9 +141,12 @@ class Permissions(BaseFlags):
self.value = permissions self.value = permissions
for key, value in kwargs.items(): for key, value in kwargs.items():
if key not in self.VALID_FLAGS: try:
raise TypeError(f'{key!r} is not a valid permission name.') flag = self.VALID_FLAGS[key]
setattr(self, key, value) except KeyError:
raise TypeError(f'{key!r} is not a valid permission name.') from None
else:
self._set_flag(flag, value)
def is_subset(self, other: Permissions) -> bool: def is_subset(self, other: Permissions) -> bool:
"""Returns ``True`` if self has the same or fewer permissions as other.""" """Returns ``True`` if self has the same or fewer permissions as other."""
@ -360,8 +363,9 @@ class Permissions(BaseFlags):
A list of key/value pairs to bulk update permissions with. A list of key/value pairs to bulk update permissions with.
""" """
for key, value in kwargs.items(): for key, value in kwargs.items():
if key in self.VALID_FLAGS: flag = self.VALID_FLAGS.get(key)
setattr(self, key, value) if flag is not None:
self._set_flag(flag, value)
def handle_overwrite(self, allow: int, deny: int) -> None: def handle_overwrite(self, allow: int, deny: int) -> None:
# Basically this is what's happening here. # Basically this is what's happening here.

Loading…
Cancel
Save