Skip to content

Commit

Permalink
Improve handling of ArrayFlags
Browse files Browse the repository at this point in the history
Why discord did it this way instead of as an integer bitfield like everything reasonable is unknowable, but this does less work to get to the same result.
  • Loading branch information
mikeshardmind committed Apr 4, 2023
1 parent ab287e7 commit ade4b3d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from __future__ import annotations

from functools import reduce
from operator import or_
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, Iterator, List, Optional, Tuple, Type, TypeVar, overload

from .enums import UserFlags
Expand Down Expand Up @@ -1566,7 +1567,7 @@ class ArrayFlags(BaseFlags):
@classmethod
def _from_value(cls: Type[Self], value: List[int]) -> Self:
self = cls.__new__(cls)
self.value = reduce(lambda a, b: a | (1 << b - 1), value, 0)
self.value = reduce(or_, map((1).__lshift__, value), 0) >> 1
return self

def to_array(self) -> List[int]:
Expand Down

0 comments on commit ade4b3d

Please sign in to comment.