From 66bdab797de87c0ca9cb4d6eaaec04d35a0f532d Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Wed, 27 Jul 2022 15:10:22 -0400 Subject: [PATCH] Bitmask: add __eq__ method --- bitmask.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bitmask.py b/bitmask.py index 69104d0..c78c6b4 100644 --- a/bitmask.py +++ b/bitmask.py @@ -120,6 +120,15 @@ class Bitmask: return f"{_fullname(self)}({args})" + def __eq__(self, other): + """Check equality.""" + if not issubclass(type(other), type(self)): + return False + elif not issubclass(other.AllFlags, self.AllFlags): + return False + else: + return other.value == self.value + def _flag_op(self, flag, op): """Apply a single flag to the bitmask. @@ -147,7 +156,7 @@ class Bitmask: for flag in other: new_bitmask._flag_op(flag, op) elif issubclass(type(other), self.AllFlags): - new_bitmask._flag_op(flag, op) + new_bitmask._flag_op(other, op) else: raise TypeError(f"can only apply {type(self)} or {self.AllFlags} (not '{type(other)}') to {type(self)}")