Document the change in behaviour of bool(flag_obj)

This commit is contained in:
Jakub Kuczys 2023-05-13 20:13:55 +02:00 committed by GitHub
parent 8d047d9e1d
commit ca0b444047
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 0 deletions

View File

@ -239,6 +239,12 @@ 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.
.. describe:: bool(b)
Returns whether any flag is set to ``True``.
.. versionadded:: 2.0
Attributes
-----------
value: :class:`int`
@ -361,6 +367,12 @@ 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.
.. describe:: bool(b)
Returns whether any flag is set to ``True``.
.. versionadded:: 2.0
.. versionadded:: 1.3
Attributes
@ -509,6 +521,12 @@ class PublicUserFlags(BaseFlags):
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
.. describe:: bool(b)
Returns whether any flag is set to ``True``.
.. versionadded:: 2.0
.. versionadded:: 1.4
Attributes
@ -693,6 +711,12 @@ 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.
.. describe:: bool(b)
Returns whether any intent is enabled.
.. versionadded:: 2.0
Attributes
-----------
value: :class:`int`
@ -1278,6 +1302,12 @@ 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.
.. describe:: bool(b)
Returns whether any flag is set to ``True``.
.. versionadded:: 2.0
Attributes
-----------
value: :class:`int`
@ -1421,6 +1451,10 @@ class ApplicationFlags(BaseFlags):
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
.. describe:: bool(b)
Returns whether any flag is set to ``True``.
.. versionadded:: 2.0
Attributes
@ -1556,6 +1590,10 @@ class ChannelFlags(BaseFlags):
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
.. describe:: bool(b)
Returns whether any flag is set to ``True``.
.. versionadded:: 2.0
Attributes
@ -1652,6 +1690,10 @@ class AutoModPresets(ArrayFlags):
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
.. describe:: bool(b)
Returns whether any flag is set to ``True``.
Attributes
-----------
value: :class:`int`
@ -1736,6 +1778,10 @@ class MemberFlags(BaseFlags):
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
.. describe:: bool(b)
Returns whether any flag is set to ``True``.
Attributes
-----------

View File

@ -119,6 +119,12 @@ class Permissions(BaseFlags):
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
.. describe:: bool(b)
Returns whether the permissions object has any permissions set to ``True``.
.. versionadded:: 2.0
Attributes
-----------
value: :class:`int`

View File

@ -1006,6 +1006,20 @@ Due to a breaking API change by Discord, :meth:`Guild.bans` no longer returns a
async for ban in guild.bans(limit=1000):
...
Flag classes now have a custom ``bool()`` implementation
--------------------------------------------------------
To allow library users to easily check whether an instance of a flag class has any flags enabled,
using `bool` on them will now only return ``True`` if at least one flag is enabled.
This means that evaluating instances of the following classes in a bool context (such as ``if obj:``) may no longer return ``True``:
- :class:`Intents`
- :class:`MemberCacheFlags`
- :class:`MessageFlags`
- :class:`Permissions`
- :class:`PublicUserFlags`
- :class:`SystemChannelFlags`
Function Signature Changes
----------------------------