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 the is operator for safety reasons.

property name: str[source]#

Return the name of the enum member as a str.

property value[source]#

Return the value of the enum member.

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 constant int 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 individual 1 and 0 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 the is 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 of int.

property name: str[source]#

Return the name of the flag combination as a str.

property value: int[source]#

Return the int value of the flag.

all(*flags)[source]#

Check if all of the given flags are part of this value.

Returns:
bool

True if any of the given flags are part of this value. Otherwise, return False.

any(*flags)[source]#

Check if any of the given flags are part of this value.

Returns:
bool

True if any of the given flags are part of this value. Otherwise, return False.

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.

invert()[source]#

Return a set of all flags not in the current set.

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 returns True.

is_subset(other)[source]#

Return whether another set contains this set or not.

Equivalent to using the “in” operator.

is_superset(other)[source]#

Return whether this set contains another set or not.

none(*flags)[source]#

Check if none of the given flags are part of this value.

Note

This is essentially the opposite of Flag.any.

Returns:
bool

True if none of the given flags are part of this value. Otherwise, return False.

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

symmetric_difference(other)[source]#

Return a set with the symmetric differences of two flag sets.

Equivalent to using the “XOR” ^ operator.

For a ^ b, this can be considered the same as (a - b) | (b - a).

union(other)[source]#

Return a combination of all flags in this set and the other set.

Equivalent to using the “OR” operator.

class hikari.internal.enums.deprecated(value, /, *, removal_version)[source]#

Used to denote that an enum member is a deprecated alias of another.