Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add additional operations to BaseFlags #1486

Merged
merged 16 commits into from
Jul 12, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: correct type annotations and documentation formatting
  • Loading branch information
celsiusnarhwal committed Jul 11, 2022
commit 9ccb2d27bdf92c3649d4b355627e06731d4f6901
67 changes: 33 additions & 34 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
Tuple,
Type,
TypeVar,
Union,
overload,
)

import discord
from .enums import UserFlags

__all__ = (
Expand Down Expand Up @@ -174,10 +174,10 @@ def __sub__(self, other):
def __invert__(self):
return self.__class__._from_value(~self.value)

__rand__: Callable[[BaseFlags], bool] = __and__
__ror__: Callable[[BaseFlags], bool] = __or__
__radd__: Callable[[BaseFlags], bool] = __add__
__rsub__: Callable[[BaseFlags], bool] = __sub__
__rand__: Callable[[Union[BaseFlags, flag_value]], bool] = __and__
__ror__: Callable[[Union[BaseFlags, flag_value]], bool] = __or__
__radd__: Callable[[Union[BaseFlags, flag_value]], bool] = __add__
__rsub__: Callable[[Union[BaseFlags, flag_value]], bool] = __sub__

def _has_flag(self, o: int) -> bool:
return (self.value & o) == o
Expand Down Expand Up @@ -216,18 +216,17 @@ class SystemChannelFlags(BaseFlags):
Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.

Adds two flags together.
.. describe:: x + y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Adds two flags together.

Subtracts two flags from each other.
.. describe:: x - y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Subtracts two flags from each other.

Returns the intersection of two flags.
.. describe:: x & y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Returns the intersection of two flags.

Returns the inverse of a flag.
.. describe:: ~x
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved

Returns the inverse of a flag.

Attributes
-----------
Expand Down Expand Up @@ -302,17 +301,17 @@ class MessageFlags(BaseFlags):
Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.

Adds two flags together.
.. describe:: x + y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Adds two flags together.
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved

Subtracts two flags from each other.
.. describe:: x - y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Subtracts two flags from each other.

Returns the intersection of two flags.
.. describe:: x & y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Returns the intersection of two flags.

Returns the inverse of a flags.
.. describe:: ~x
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Returns the inverse of a flag.


.. versionadded:: 1.3
Expand Down Expand Up @@ -411,17 +410,17 @@ class PublicUserFlags(BaseFlags):
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.

Adds two flags together.
.. describe:: x + y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Adds two flags together.
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved

Subtracts two flags from each other.
.. describe:: x - y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Subtracts two flags from each other.

Returns the intersection of two flags.
.. describe:: x & y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Returns the intersection of two flags.

Returns the inverse of a flag.
.. describe:: ~x
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Returns the inverse of a flag.


.. versionadded:: 1.4
Expand Down Expand Up @@ -568,17 +567,17 @@ class Intents(BaseFlags):
Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.

Adds two flags together.
.. describe:: x + y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Adds two flags together.
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved

Subtracts two flags from each other.
.. describe:: x - y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Subtracts two flags from each other.

Returns the intersection of two flags.
.. describe:: x & y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Returns the intersection of two flags.

Returns the inverse of a flag.
.. describe:: ~x
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Returns the inverse of a flag.


Attributes
Expand Down Expand Up @@ -1121,17 +1120,17 @@ class MemberCacheFlags(BaseFlags):
Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.

Adds two flags together.
.. describe:: x + y
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
Adds two flags together.
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved

Subtracts two flags from each other.
.. describe:: x - y
Subtracts two flags from each other.

Returns the intersection of two flags.
.. describe:: x & y
Returns the intersection of two flags.

Returns the inverse of a flag.
.. describe:: ~x
Returns the inverse of a flag.

Attributes
-----------
Expand Down Expand Up @@ -1258,17 +1257,17 @@ class ApplicationFlags(BaseFlags):
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.

Adds two flags together.
.. describe:: x + y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Adds two flags together.
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved

Subtracts two flags from each other.
.. describe:: x - y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Subtracts two flags from each other.

Returns the intersection of two flags.
.. describe:: x & y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Returns the intersection of two flags.

Returns the inverse of a flag.
.. describe:: ~x
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Returns the inverse of a flag.

.. versionadded:: 2.0

Expand Down Expand Up @@ -1368,17 +1367,17 @@ class ChannelFlags(BaseFlags):
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.

Adds two flags together.
.. describe:: x + y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Adds two flags together.
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved

Subtracts two flags from each other.
.. describe:: x - y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Subtracts two flags from each other.

Returns the intersection of two flags.
.. describe:: x & y
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Returns the intersection of two flags.

Returns the inverse of a flag.
.. describe:: ~x
celsiusnarhwal marked this conversation as resolved.
Show resolved Hide resolved
Returns the inverse of a flag.

.. versionadded:: 2.0

Expand Down