From fe2bfd9356a279cf01c1da2b40bdccf6044a0eaa Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Wed, 27 Jul 2022 22:07:15 -0400 Subject: [PATCH] bitmask.py: clarify logic on discard, remove --- bitmask.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bitmask.py b/bitmask.py index c78c6b4..5ace01c 100644 --- a/bitmask.py +++ b/bitmask.py @@ -173,6 +173,13 @@ class Bitmask: def __radd__(self, other): return self.__add__(other) + def discard(self, flag): + """Remove flag bitmask if present. + + This behaves the same as built-in `set.discard()`. + """ + self._flag_op(flag, lambda a, b : a & ~b) + def remove(self, flag): """Remove `flag` from the bitmask. @@ -183,12 +190,4 @@ class Bitmask: """ if not flag in self: raise KeyError(flag) - self._flag_op(flag, lambda a, b : a ^ b) - - def discard(self, flag): - """Remove flag bitmask if present. - - This behaves the same as built-in `set.discard()`. - """ - if flag in self: - self.remove(flag) + self.discard(flag)