``Flag`` is the same as :class:`Enum`, but its members support the bitwise
operators ``&`` (*AND*), ``|`` (*OR*), ``^`` (*XOR*), and ``~`` (*INVERT*);
- the results of those operators are members of the enumeration.
+ the results of those operations are (aliases of) members of the enumeration.
.. method:: __contains__(self, value)
spam = nonmember(SpamEnumIsInner)
self.assertTrue(SpamEnum.spam is SpamEnumIsInner)
+ def test_using_members_as_nonmember(self):
+ class Example(Flag):
+ A = 1
+ B = 2
+ ALL = nonmember(A | B)
+
+ self.assertEqual(Example.A.value, 1)
+ self.assertEqual(Example.B.value, 2)
+ self.assertEqual(Example.ALL, 3)
+ self.assertIs(type(Example.ALL), int)
+
+ class Example(Flag):
+ A = auto()
+ B = auto()
+ ALL = nonmember(A | B)
+
+ self.assertEqual(Example.A.value, 1)
+ self.assertEqual(Example.B.value, 2)
+ self.assertEqual(Example.ALL, 3)
+ self.assertIs(type(Example.ALL), int)
+
def test_nested_classes_in_enum_with_member(self):
"""Support locally-defined nested classes."""
class Outer(Enum):