Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def permissions_for(self, obj: Union[Member, Role], /) -> Permissions:
if obj.is_default():
return base

overwrite = utils.get(self._overwrites, type=_Overwrites.ROLE, id=obj.id)
overwrite = utils.find(lambda ow: ow.type == _Overwrites.ROLE and ow.id == obj.id, self._overwrites)
if overwrite is not None:
base.handle_overwrite(overwrite.allow, overwrite.deny)

Expand Down
27 changes: 15 additions & 12 deletions discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
TYPE_CHECKING,
)
import unicodedata
import collections.abc
from itertools import islice
from base64 import b64encode, b64decode
from bisect import bisect_left
import datetime
Expand Down Expand Up @@ -89,7 +91,7 @@
_ZSTD_SOURCE = 'zstandard'
except ImportError:
try:
from compression.zstd import ZstdDecompressor # type: ignore

Check warning on line 94 in discord/utils.py

View workflow job for this annotation

GitHub Actions / check 3.x

Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)

_ZSTD_SOURCE = 'compression.zstd'
except ImportError:
Expand Down Expand Up @@ -434,7 +436,7 @@


def _find(predicate: Callable[[T], Any], iterable: Iterable[T], /) -> Optional[T]:
return next((element for element in iterable if predicate(element)), None)
return next(filter(predicate, iterable), None)


async def _afind(predicate: Callable[[T], Any], iterable: AsyncIterable[T], /) -> Optional[T]:
Expand Down Expand Up @@ -659,7 +661,7 @@
def _to_json(obj: Any) -> str:
return orjson.dumps(obj).decode('utf-8')

_from_json = orjson.loads # type: ignore

Check warning on line 664 in discord/utils.py

View workflow job for this annotation

GitHub Actions / check 3.x

Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)

else:

Expand Down Expand Up @@ -1037,17 +1039,18 @@


def _chunk(iterator: Iterable[T], max_size: int) -> Iterator[List[T]]:
ret = []
n = 0
for item in iterator:
ret.append(item)
n += 1
if n == max_size:
yield ret
ret = []
n = 0
if ret:
yield ret
# Specialise iterators that can be sliced as it is much faster
if isinstance(iterator, collections.abc.Sequence):
for i in range(0, len(iterator), max_size):
yield list(iterator[i : i + max_size])
else:
# Fallback to slower path
iterator = iter(iterator)
while True:
batch = list(islice(iterator, max_size))
if not batch:
break
yield batch


async def _achunk(iterator: AsyncIterable[T], max_size: int) -> AsyncIterator[List[T]]:
Expand Down Expand Up @@ -1163,7 +1166,7 @@
args = tp.__args__
if not hasattr(tp, '__origin__'):
if PY_310 and tp.__class__ is types.UnionType: # type: ignore
converted = Union[args] # type: ignore

Check warning on line 1169 in discord/utils.py

View workflow job for this annotation

GitHub Actions / check 3.x

Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)
return evaluate_annotation(converted, globals, locals, cache)

return tp
Expand Down
Loading