Python 3.6 has added Flag
and IntFlag
which support the usual bit-wise operations. As a bonus, the resulting values from the bit-wise operations are still members of the original flag class, and are singletons [1].
The aenum
library also has this addition and is usable back to Python 2.7.
[1] A bug exists in 3.6.0: if the pseudo-flag members are being created in threads then there is no guarantee that you won’t end up with duplicates; this is fixed in 3.6.1 (and never existed in aenum
).