Enum Parser Implementation¶
Parser implementations for standard library and disnake enums and flags.
Classes¶
- class disnake_compass.impl.parser.enum.EnumParser(enum_class, *, store_by_value=None)[source]¶
Bases:
Parser[_EnumT]Parser type for enums and flags.
Enums and flags are stored by value instead of by name. This makes parsing a bit slower, but values are generally shorter than names.
This parser type works for standard library and disnake enums and flags. Note that this only works for enums and flags where all values are of the same type.
- Parameters:
enum_class (
type[_EnumT]) – The enum or flag class to use for parsing.store_by_value (
bool|None) –Whether
loads()anddumps()expect the enum value type or a string.For enum types where the members are not all of the same type, this must be
False.For enum types where all members are integers, this defaults to
True, otherwise this defaults toFalse.
Attributes¶
Methods¶
- await dumps(argument)[source]¶
Dump an enum member into a string.
Note
If
store_by_valueis True, this dumps the name of the enum member passed asargument; otherwise, this dumps its value.- Parameters:
argument (
_EnumT) – The value that is to be dumped.
- await loads(argument, /)[source]¶
Load an enum member from a string.
This uses the underlying
value_parser.Note
If
store_by_valueis True, theargumentis expected to be the value of an enum member; otherwise, theargumentis expted to be the name.- Parameters:
argument (
str) –The value that is to be loaded into a channel.
This always matches the channel type of the parser.
- disnake_compass.impl.parser.enum.FlagParser[source]¶
alias of
EnumParser