Flags and FlagSet#
When working with flags in general, it is recommended to use the construct adapter provided by this sub module.
- umbrella.flags.from_flags(cls: Iterable[E], flags: int, mask: int = -1) E [source]#
Retrieves an enum value from the given flag
- Parameters:
cls (t.Iterable[E]) – the enum class
flags (int) – one or multiple flags
mask (int, optional) – the mask to apply to the provided flags, defaults to ~0
- Returns:
either the enum value or returns the original if no suitable representation has been found.
- Return type:
E | int
- class umbrella.flags.Flags(flags_ty, selector: str = 'flags_value')[source]#
An adapter to parse flag-sets.
Parsing does nothing, because this adapter uses
Computed
to retrieve the flag value. It then creates a new instance of type flags_ty and returns it.- Parameters:
flags_ty (type) – the class operating in parsed flags
selector (str, optional) – the context selector, defaults to “flags_value”
- class umbrella.flags.FlagSet(_FlagSet__flags: int)[source]#
Simple class to represent a set of flags within an integer value.
>>> flags = FlagSet(0b00010000110001) >>> flags.get_flag(0) # ^ True >>> flags.get_field(4, 2) # ^^ 3 >>> flags.get_flag(10) # ^ True
- Parameters:
__flags (int) – the flags value
- flags#
The stored flags as an integer