If I have an enum class like so:
class TestFlag(enum.Flag):
A = enum.auto()
B = enum.auto()
C = enum.auto()
D = A | B # valid
Is it possible to specify a certain combination, such as, say TestFlag.C | TestFlag.B as invalid? In other words, is there a way to ensure that writing TestFlag.C | TestFlag.B will raise an Error?
You could make use of the
_missing_method:NB: This will not catch invalid choices made during class creation, only operations that occur afterwards.
Disclosure: I am the author of the Python stdlib
Enum, theenum34backport, and the Advanced Enumeration (aenum) library.