hikari.internal.enums#
Implementation of parts of Python’s enum
protocol to be more performant.
Module Contents#
- class hikari.internal.enums.Enum[source]#
Clone of Python’s
enum.Enum
implementation.This is designed to be faster and more efficient than Python’s implementation, while retaining the majority of the external interface that Python’s
enum.Enum
provides.An
Enum
is a simple class containing a discrete set of constant values that can be used in place of this type. This acts as a type-safe way of representing a set number of “things”.Warning
Some semantics such as subtype checking and instance checking may differ. It is recommended to compare these values using the
==
operator rather than theis
operator for safety reasons.
- class hikari.internal.enums.Flag[source]#
Clone of Python’s
enum.Flag
implementation.This is designed to be faster and more efficient than Python’s implementation, while retaining the majority of the external interface that Python’s
enum.Flag
provides.In simple terms, an
Flag
is a set of wrapped constantint
values that can be combined in any combination to make a special value. This is a more efficient way of combining things like permissions together into a single integral value, and works by setting the individual1
and0
on the binary representation of the integer.This implementation has extra features, in that it will actively behave like a
set
as well.Warning
It is important to keep in mind that some semantics such as subtype checking and instance checking may differ. It is recommended to compare these values using the
==
operator rather than theis
operator for safety reasons.Especially where pseudo-members created from combinations are cached, results of using of
is
may not be deterministic. This is a side effect of some internal performance improvements.Failing to observe this __will__ result in unexpected behaviour occurring in your application!
Also important to note is that despite wrapping
int
values, conceptually this does not behave as if it were a subclass ofint
.- difference(other)[source]#
Perform a set difference with the other set.
This will return all flags in this set that are not in the other value.
Equivalent to using the subtraction
-
operator.
- intersection(other)[source]#
Return a combination of flags that are set for both given values.
Equivalent to using the “AND”
&
operator.
- is_disjoint(other)[source]#
Return whether two sets have a intersection or not.
If the two sets have an intersection, then this returns
False
. If no common flag values exist between them, then this returnsTrue
.
- is_subset(other)[source]#
Return whether another set contains this set or not.
Equivalent to using the “in” operator.
- none(*flags)[source]#
Check if none of the given flags are part of this value.
Note
This is essentially the opposite of
Flag.any
.
- split()[source]#
Return a list of all defined atomic values for this flag.
Any unrecognised bits will be omitted for brevity.
The result will be a name-sorted
typing.Sequence
of each member