if other_value is NotImplemented:
return NotImplemented
- for flag in self, other:
- if self._get_value(flag) is None:
- raise TypeError(f"'{flag}' cannot be combined with other flags with |")
value = self._value_
+ # _get_value(self) is self._value_ and _get_value(other) is
+ # other_value, so only walk the operands (to raise on the offending
+ # flag) when one of those values is actually None.
+ if value is None or other_value is None:
+ for flag in self, other:
+ if self._get_value(flag) is None:
+ raise TypeError(f"'{flag}' cannot be combined with other flags with |")
return self.__class__(value | other_value)
def __and__(self, other):
if other_value is NotImplemented:
return NotImplemented
- for flag in self, other:
- if self._get_value(flag) is None:
- raise TypeError(f"'{flag}' cannot be combined with other flags with &")
value = self._value_
+ if value is None or other_value is None:
+ for flag in self, other:
+ if self._get_value(flag) is None:
+ raise TypeError(f"'{flag}' cannot be combined with other flags with &")
return self.__class__(value & other_value)
def __xor__(self, other):
if other_value is NotImplemented:
return NotImplemented
- for flag in self, other:
- if self._get_value(flag) is None:
- raise TypeError(f"'{flag}' cannot be combined with other flags with ^")
value = self._value_
+ if value is None or other_value is None:
+ for flag in self, other:
+ if self._get_value(flag) is None:
+ raise TypeError(f"'{flag}' cannot be combined with other flags with ^")
return self.__class__(value ^ other_value)
def __invert__(self):