I would like to define a set of flags (subclassed from enum.Flag
), with some flags which are defined based on others. This is similar to the white flag in the example: https://docs.python.org/3/library/enum.html#flag, but it is not just a combinations of previous flags, but needs its own value too.
My first attempt was:
from enum import Flag, auto
class MyFlag(Flag):
NONE = 0
DEFAULT = auto()
FIRST = auto() | DEFAULT
SECOND = auto() | DEFAULT
THIRD = auto()
ANY = FIRST | SECOND | THIRD
But this raised an error:
TypeError: unsupported operand type(s) for |: 'auto' and 'int'
The working implementation should give:
>>> print(bool(MyFlag.FIRST & MyFlag.DEFAULT))
# prints True
>>> print(bool(MyFlag.THIRD & MyFlag.DEFAULT))
# prints False